2
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?

Lycan22
  • 160
  • 1
  • 8
  • 2
    [This post](http://stackoverflow.com/questions/38774922/prevent-numpy-from-creating-a-multidimensional-array/38776674#38776674) is similar and may provide some of the answers you are seeking. – Paul Panzer Mar 10 '17 at 00:46
  • 1
    If you need "staggered" array you shouldn't use `numpy`, just use plain python lists. – juanpa.arrivillaga Mar 10 '17 at 00:47

0 Answers0