Just to review the 1d case:
In [33]: x = np.array([[1,2],[1,2,3]])
In [34]: x.shape
Out[34]: (2,)
In [35]: x
Out[35]: array([list([1, 2]), list([1, 2, 3])], dtype=object)
The result is a 2 element array of lists, where as we started with a list of lists. Not much difference.
But note that if the lists are same size, np.array creates a numeric 2d array:
In [36]: x = np.array([[1,2,4],[1,2,3]])
In [37]: x
Out[37]:
array([[1, 2, 4],
[1, 2, 3]])
So don't count on the behavior we see in [33].
I could create a 2d object array:
In [59]: x = np.empty((2,2),object)
In [60]: x
Out[60]:
array([[None, None], # in this case filled with None
[None, None]], dtype=object)
I can assign each element with a different kind and size of object:
In [61]: x[0,0] = np.arange(3)
In [62]: x[0,0] = [1,2,3]
In [63]: x[1,0] = 'abc'
In [64]: x[1,1] = np.arange(6).reshape(2,3)
In [65]: x
Out[65]:
array([[list([1, 2, 3]), None],
['abc', array([[0, 1, 2],
[3, 4, 5]])]], dtype=object)
It is still 2d. For most purposes it is like a list or list of lists, containing objects. The databuffer actually has pointers to objects stored else where in memory (just as list buffer does).
There really isn't such a thing as a 3d array with a variable last dimension. At best we can get a 2d array that contains lists or arrays of various sizes.
Make a list of 2 2d arrays:
In [69]: alist = [np.arange(6).reshape(2,3), np.arange(4.).reshape(2,2)]
In [70]: alist
Out[70]:
[array([[0, 1, 2],
[3, 4, 5]]), array([[0., 1.],
[2., 3.]])]
In this case, giving it to np.array raises an error:
In [71]: np.array(alist)
---------------------------------------------------------------------------
ValueError: could not broadcast input array from shape (2,3) into shape (2)
We could fill an object array with elements from this list:
In [72]: x = np.empty((4,),object)
In [73]: x[0]=alist[0][0]
In [74]: x[1]=alist[0][1]
In [75]: x[2]=alist[1][0]
In [76]: x[3]=alist[1][1]
In [77]: x
Out[77]:
array([array([0, 1, 2]), array([3, 4, 5]), array([0., 1.]),
array([2., 3.])], dtype=object)
and reshape it to 2d
In [78]: x.reshape(2,2)
Out[78]:
array([[array([0, 1, 2]), array([3, 4, 5])],
[array([0., 1.]), array([2., 3.])]], dtype=object)
Result is a 2d array containing 1d arrays. To get the shapes of the elements I have to do something like:
In [87]: np.frompyfunc(lambda i:i.shape, 1,1)(Out[78])
Out[87]:
array([[(3,), (3,)],
[(2,), (2,)]], dtype=object)
array([array([1, 2, 3]), array([1, 2])], dtype=object). This means that you are getting a one dimensional array of objects, which are in this case np.ndarray objects. As for as I am aware it is not possible to allocate an array without a fixed dimension in any direction.xas (2,2) object dtype, and set the the elements fromx1andx2. But it is tricky to do this without getting broadcasting errors,