a = np.array([[1,2],[3,4],[5,6]])
a.shape
(3, 2)
a = np.array([[1,2],[3,4],[5]])
(3,)
# nd array of nd arrays.
a = np.array([np.array([1,2]),np.array([3,4]),np.array([5])])
a.shape
(3,)
a = np.array([np.array([1,2]),np.array([3,4]),np.array([5,6])])
a.shape
(3, 2)
np.version.version
'1.11.1'
I have been trying to wrap my head around this behavior. I can't seem to find anything in the numpy documentation.
Basically if I pass lists or ndarrays of equal length to np.array
I get a 2 dimensional matrix but if pass lists of ndarrays of different lengths to np.array
I get a single dimension (ndarray of ndarrays).
I was expecting both to give me an ndarray of ndarrays or lists. How does numpy.array
decide to take ndarrays or lists of same lengths and convert them into a 2-D ndarray? Does anyone know if this behavior is documented somewhere?