I have two simple one-dimensional arrays in NumPy. I should be able to concatenate them using numpy.concatenate. But I get this error for the code below:
TypeError: only length-1 arrays can be converted to Python scalars
Code
import numpy
a = numpy.array([1, 2, 3])
b = numpy.array([5, 6])
numpy.concatenate(a, b)
Why?
np.concatenat(..., axis)
. If you want to stack them vertically, usenp.vstack
. If you want to stack them (into multiple arrays) horizontally, usenp.hstack
. (If you want to stack them depth-wise, i.e. teh 3rd dimension, usenp.dstack
). Note that the latter are similar to pandaspd.concat
– smci