[Numpy-discussion] np.ma.argmax not respecting the mask?
Pierre Gerard-Marchant
pgmdevlist at gmail.com
Tue Jul 9 10:26:08 EDT 2013
On Jul 9, 2013, at 16:08 , Sebastian Berg <sebastian at sipsolutions.net> wrote:
> On Tue, 2013-07-09 at 15:14 +0200, Stéfan van der Walt wrote:
>> On Tue, Jul 9, 2013 at 2:55 PM, Chao YUE <chaoyuejoy at gmail.com> wrote:
>>> I am using 1.7.1 version of numpy and np.ma.argmax is not repecting the
>>> mask?
>>>
>>> In [96]: d3
>>> Out[96]:
>>> masked_array(data =
>>> [[-- -- -- -- 4]
>>> [5 -- 7 8 9]],
>>> mask =
>>> [[ True True True True False]
>>> [False True False False False]],
>>> fill_value = 6)
>>>
>>>
>>> In [97]: np.ma.argmax(d3,axis=0)
>>> Out[97]: array([1, 0, 1, 1, 1])
>>
>> This is the result I would expect. If both values are masked, the
>> fill value is used, so there is always an argmin value.
>>
>
> To be honest, I would expect the exact opposite. If there is no value,
> there is no minimum argument -> either its an error, or it signals
> invalid in some other way. On masked arrays I would expect it to be
> masked to signal this.
The doc is quite clear: masked values are replaced by `fill_value` when determining the argmax/argmin. Attaching a mask a posteriori is always doable, but making the output of np.ma.argstuff a MaskedArray may be a nuisance at this point (any input from heavy users?).
More information about the NumPy-Discussion
mailing list