Recently, I've faced the problem with np.array(list) conversion. Assume we have a list of 3 numpy 2D arrays with shapes (x, y), (x, y), (x, z) so that shape[0] is the same for all arrays in the list. In that case, conversion to array fails with
ValueError: could not broadcast input array from shape (x, z) into shape (x)
Numpy tries to create and array of shape (3, x, y) instead of leaving it list-like structure (array of different arrays).
If at least one shape[0] differs from the other, we get what we want, array of arrays with shape (3,)
I overcame that problem by adding an element of different type to list, and using np.array(list)[:-1]. So, is it a bug, or I missed something (like np.array() params, etc.)?
Some examples:
>>> import numpy as np
>>> x = np.ones((3,2))
>>> y = np.ones((3,2))
>>> z = np.ones((3,3))
>>> a = np.ones((2,3))
>>> xyz = np.array([x,y,z])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: could not broadcast input array from shape (3,2) into shape (3)
>>> xza = np.array([x,z,a])
[array([[ 1., 1.],
[ 1., 1.],
[ 1., 1.]])
array([[ 1., 1., 1.],
[ 1., 1., 1.],
[ 1., 1., 1.]])
array([[ 1., 1., 1.],
[ 1., 1., 1.]])]
>>> xyz2 = np.array([x,y,z,'tmp'])[:-1]
[array([[ 1., 1.],
[ 1., 1.],
[ 1., 1.]])
array([[ 1., 1.],
[ 1., 1.],
[ 1., 1.]])
array([[ 1., 1., 1.],
[ 1., 1., 1.],
[ 1., 1., 1.]])]