[Numpy-discussion] ndarray with double comparison

Marc Shivers marc.shivers at gmail.com
Thu Oct 13 12:50:12 EDT 2011


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)

On Thu, Oct 13, 2011 at 12:13 PM, Chao YUE <chaoyuejoy at gmail.com> wrote:

> Dear all,
>
> sorry for this stupid question but I cannot find it in numpy tutorial or
> google.
> suppose I have a=np.arange(11).
>
> In [32]: a < 8
> Out[32]:
> array([ True,  True,  True,  True,  True,  True,  True,  True, False,
>        False, False], dtype=bool)
>
> In [34]: a > 4
> Out[34]:
> array([False, False, False, False, False,  True,  True,  True,  True,
>         True,  True], dtype=bool)
>
> how can I have boolean index like 4 < a < 8
> np.where(a>4 and a<8);or plainly input "a>4 and a<8" doesn't work.
>
> thanks,
>
> Chao
>
> --
>
> ***********************************************************************************
> 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
>
> ************************************************************************************
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20111013/a250382a/attachment.html>


More information about the NumPy-Discussion mailing list