What does numpy.concatenate do with a single argument?

Viewed 273

I have read about concatenate. But, did not see the function taking a single list as input.It must have two lists as input.

Consider the following statement in a program that I want to execute

row = np.concatenate(row, 1)

What is concatenate doing here? It is taking only one list named row.

2 Answers

Probably you have seen it most often used like this:

c = np.concatenate([a, b])

but you can of course also do:

ab = [a, b]
c = np.concatenate(ab)

Look at row before and after concatenating to see what is going on.

The first argument of np.concatenate is supposed to be a sequence of objects (think vectors or matrices). The second argument is the axis along which the concatenation is to be performed. See help(np.concatenate) for the full docstring.

For your command to be valid, the objects in the row sequence must have at least a 0th and a 1st dimension. This would typically be a matrix, but the name row is suggestive of a set of row vectors that have dimension [0, d].

If you concatenate n vectors of shape [0, d] along the 1st dimension, this will result in an object of shape [0, n*d]. Which is a very long row vector.

Related