The vec.shape means that the array has 3 items. But they are dtype object, that is, pointers to items else where in memory.
Apparently the items are arrays themselves. One of the concatenate or stack functions can join them into one array, provided the dimensions match.
I'd suggest printing
[x.shape for x in vec]
to verify the shape. And of course make sure that those sub arrays are not, themselves object dtypes.
In [261]: vec = np.empty(3, object)
In [262]: vec[:] = [np.arange(10), np.ones(10), np.zeros(10)]
In [263]: vec
Out[263]:
array([array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),
array([ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]),
array([ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])], dtype=object)
In [264]: vec.reshape(3,10)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-264-cd555975140c> in <module>()
----> 1 vec.reshape(3,10)
ValueError: cannot reshape array of size 3 into shape (3,10)
In [265]: [x.shape for x in vec]
Out[265]: [(10,), (10,), (10,)]
In [266]: np.stack(vec)
Out[266]:
array([[ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9.],
[ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]])
In [267]: np.concatenate(vec)
Out[267]:
array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0.])
In [268]: np.concatenate(vec).reshape(3,10)
Out[268]:
array([[ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9.],
[ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]])
len is not a good test; use shape. For example if I change one array to be 2d
In [269]: vec[1]=np.ones((10,1))
In [270]: vec
Out[270]:
array([array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),
array([[ 1.],
[ 1.],
[ 1.],
[ 1.],
[ 1.],
[ 1.],
[ 1.],
[ 1.],
[ 1.],
[ 1.]]),
array([ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])], dtype=object)
In [271]: [len(x) for x in vec]
Out[271]: [10, 10, 10]
In [272]: [x.shape for x in vec]
Out[272]: [(10,), (10, 1), (10,)]
In [273]: np.concatenate(vec)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-273-a253d8b9b25d> in <module>()
----> 1 np.concatenate(vec)
ValueError: all the input arrays must have same number of dimensions
np.concatenate(vec).reshape(3,150)?vec.dtypeyieldsdtype('O')type(vec[0])?numpy.ndarrayValueError: all the input arrays must have same number of dimensionsif I trynp.concatenate- which is strange because I have inspected all my vectors and they all have 150 elements of typedtype=float32