[Numpy-discussion] Expected behavior of numpy object arrays. Is this a bug?

Rudolph van der Merwe rudolphv at gmail.com
Thu May 17 07:52:08 EDT 2007


Can someone please confirm if the following is the expected behavior
of numpy ndarrays of dtype=object, i.e. object arrays. I suspect it
might be a bug.

In the Python shell dump below, shouldn't the dtype of oa2[0] and
oa2[1] be 'int32' as is the case for oa1[0] and oa1[1] ?


Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.__version__
'1.0.2'
>>> a = np.array([1,2], dtype='int32')
>>> b = np.array([5,6,7], dtype='int32')
>>> c = np.array([3,4], dtype='int32')
>>> oa1 = np.array([a, b], dtype=object)
>>> oa2 = np.array([a, c], dtype=object)
>>> oa1
array([[1 2], [5 6 7]], dtype=object)
>>> oa1[0]
array([1, 2])
>>> oa1[0].dtype
dtype('int32')
>>> oa1[1]
array([5, 6, 7])
>>> oa1[1].dtype
dtype('int32')
>>> oa2
array([[1, 2],
      [3, 4]], dtype=object)
>>> oa2[0]
array([1, 2], dtype=object)
>>> oa2[0].dtype
dtype('object')
>>> oa2[1]
array([3, 4], dtype=object)
>>> oa2[1].dtype
dtype('object')
>>>

-- 
Rudolph van der Merwe



More information about the NumPy-Discussion mailing list