Suppose we have:
>>> x
array([-1. , -1.3, 0. , 1.3, 0.2])
We can choose select elements with a range:
>>> x[x <= 1]
array([-1. , -1.3, 0. , 0.2])
And we can bound it below too:
>>> x[-1 <= x]
array([-1. , 0. , 1.3, 0.2])
Is there some rationale for not being able to use the following:
>>> x[-1 <= x <= 1]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
I know that all it does is create a mask of True
and False
s upon doing these inequality operations, and so I can do the following:
>>> x[(-1 <= x) * (x <= 1)]
array([-1. , 0. , 0.2])
as a broadcasting operation on booleans. It's not too inconvenient, but why doesn't the previous range inequality work?