[Numpy-discussion] non-intuitive behaviour in numpy.array([list], numpy.object_)

Garnet Chan gkc1000@gmail....
Thu Jan 3 09:08:34 CST 2008

When constructing an numpy object array from a list of numpy arrays,
one observes the following behaviour

>>> import numpy as N
>>> a=[N.zeros([2,2], N.object_), N.zeros([2,2], N.object_)]
>>> b=N.array(a, N.object_)
>>> print b.shape
(2, 2, 2)
>>> a=[N.zeros([2,2], N.object_), N.zeros([2,1], N.object_)]
>>> b=N.array(a, N.object_)
>>> print b.shape

I understand that this is because in the 1st instance, numpy is trying
to be clever and recognises that the list of arrays "a" can be
reshaped into a 3-d array. But surely, if we are constructing an array
with the object_ dtype, the first should also be converted into a
shape (2,) array?

More information about the Numpy-discussion mailing list