[Numpy-discussion] Priority rules between 0d array and np.scalar
Thu Nov 20 08:24:07 CST 2008
That time of a month again: could anybody (and I'm thinking about you
in particular, Travis O.) can explain me what the priority rules are
between a 0d ndarray and a np.scalar ?
OK, I understand there are no real rules. However, the bug I was
describing in a previous thread (firstname.lastname@example.org
/msg13235.html) is still around:
When multiplying/adding a np.scalar and ma.masked, the result varies
depending on the order of the arguments as well as on their dtype.
(Keep in mind that ma.masked is a subclass 0d ndarray of value 0 and
dtype np.float64, with a __array_priority__ of 15).
ma.masked * np.float32(1) => ma.masked
np.float32(1) * ma.masked => ma.masked
ma.masked * np.float64(1) => ma.masked
np.floa64(1) * ma.masked => 0
My understanding is that for the first 2 operations, ma.masked takes
over because it has the higher dtype. In that case, we use the rules
defined in MaskedArray for multiplication (either __mul__ or
For the 3rd and 4th operations, the two arguments have the same dtype
and it looks like we're switching to a different priority rule.
I would have expected ma.masked to take over in both cases, because a
MaskedArray has a higher __array_priority__ than a ndarray or a
np.scalar. That's not the case: the fact that ma.masked is a subclass
of ndarray is not recognized...
I hope I didn't lose anybody in my description. A ticket has recently
been filled about the same issue:
Looking forward to hearing from y'all
More information about the Numpy-discussion