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

Chao YUE chaoyuejoy at gmail.com
Tue Jul 9 11:20:46 EDT 2013


Thanks Pierre, good to know there are so many tricks available.

Chao

On Tue, Jul 9, 2013 at 4:55 PM, Pierre Gerard-Marchant <pgmdevlist at gmail.com
> wrote:

>
> 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).
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
***********************************************************************************
Chao YUE
Laboratoire des Sciences du Climat et de l'Environnement (LSCE-IPSL)
UMR 1572 CEA-CNRS-UVSQ
Batiment 712 - Pe 119
91191 GIF Sur YVETTE Cedex
Tel: (33) 01 69 08 29 02; Fax:01.69.08.77.16
************************************************************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130709/689486d6/attachment.html>


More information about the NumPy-Discussion mailing list