[Numpy-discussion] ndarray with double comparison
Neil
neilcrighton@gmail....
Sat Oct 15 06:05:14 CDT 2011
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
More information about the NumPy-Discussion
mailing list