[Numpy-discussion] ndarray with double comparison

Chao YUE chaoyuejoy@gmail....
Sat Oct 15 06:30:26 CDT 2011


Thanks. quite useful!!

Chao

2011/10/15 Neil <neilcrighton@gmail.com>

> Marc Shivers <marc.shivers <at> gmail.com> writes:
>
> >
> > you could use bitwise comparison with paretheses:  In [8]:
> (a>4)&(a<8)Out[8]:
> array([False, False, False, False, False,  True,  True,  True, False,
> False, False], dtype=bool)
> >
>
> For cases like this I find it very useful to define a function between() -
> e.g.
> https://bitbucket.org/nhmc/pyserpens/src/4e2cc9b656ae/utilities.py#cl-88
>
> Then you can use
>
> between(a, 4, 8)
>
> instead of
>
> (4 < a) & (a < 8),
>
> which I find less readable and more difficult to type.
>
> Neil
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@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.scipy.org/pipermail/numpy-discussion/attachments/20111015/cd0d0cfd/attachment.html 


More information about the NumPy-Discussion mailing list