[Numpy-discussion] np.ma.argmax not respecting the mask?

Pierre Gerard-Marchant pgmdevlist at gmail.com
Tue Jul 9 10:55:51 EDT 2013

On Jul 9, 2013, at 16:38 , Chao YUE <chaoyuejoy at gmail.com> wrote:

> Sorry I didn't the docs very carefully. there is no doc for np.ma.argmax for indeed there is for np.ma.argmin

Yeah, the doc of the function asks you to go check the doc of the method… Not the best.

> so it's an expected behavior rather than a bug. Let some heavy users to say their ideas.
> Practicaly, the returned value of 0 will be always confused with the values which are not masked
> but do have the minimum or maximum values at the 0 position over the specified axis.

Well, it's just an index: if you take the corresponding value from the input array, it'll be masked...

> One way to walk around is:
> data_mask = np.ma.mean(axis=0).mask
> np.ma.masked_array(np.ma.argmax(data,axis=0), mask=data_mask)

I find easier to use `mask=x.mask.prod(axis)` to get the combined mask along the desired axis (you could also use a `reduce(np.logical_and, x.mask)` for axis=0, but it's less convenient I think).

More information about the NumPy-Discussion mailing list