[Numpy-discussion] Summing an array with dtype=object

Robert Kern robert.kern@gmail....
Sun Nov 15 23:16:44 CST 2009


On Sun, Nov 15, 2009 at 23:11, Pierre GM <pgmdevlist@gmail.com> wrote:
> All,
> An issue was recently raised about summing a MaskedArray with a np.object dtype. Turns out that the problem is numpy based:
> Let's sum using integers
>>>> type(np.sum([1,2,3], dtype=np.int32))
> <type 'numpy.int32'>
>
> Now, with a np.object dtype:
>>>>  type(np.sum([1,2,3],dtype=object))
>  <type 'int'>
>
> And we no longer have a np.object, but a regular Python int. Which, unfortunately for MaskedArray, does not have a view object (hence the bug).
> Is it the expected behavior ?

Yes. Wherever we can, we return the object itself rather than
np.object_ scalars.

In [2]: a
Out[2]: array([0, 1, 2], dtype=object)

In [5]: type(a[0])
Out[5]: int


-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco


More information about the NumPy-Discussion mailing list