How come this be right?
X=np.array([range(1,12)])
A=X>4
B=X<10
C=(X>4) | (X<10)
print (X[A])
print (X[B])
print (X[C])
[ 5 6 7 8 9 10 11]
[1 2 3 4 5 6 7 8 9]
[ 1 2 3 4 5 6 7 8 9 10 11]
How come this be right?
X=np.array([range(1,12)])
A=X>4
B=X<10
C=(X>4) | (X<10)
print (X[A])
print (X[B])
print (X[C])
[ 5 6 7 8 9 10 11]
[1 2 3 4 5 6 7 8 9]
[ 1 2 3 4 5 6 7 8 9 10 11]
I'm going to guess that your concern is because you have every element in the final expression, simply because the first two are obvious (5..11 are all greater than four and 1..9 are all less than ten).
But the third one is also right since every element is either greater than four or less than ten. The numbers 1..9 are all less than ten so they're in. Similarly, 5..11 are all greater than four so they're in as well. The union of those two ranges is the entire set of values.
If you wanted the items that were between four and ten (exclusive at both ends), you should probably have used "and" instead of "or" (& instead of |):
import numpy as np
X=np.array([range(1,12)])
A=X>4
B=X<10
C=(X>4) | (X<10)
D=(X>4) & (X<10)
E=(X<=4) | (X>=10)
print (X[A])
print (X[B])
print (X[C])
print (X[D])
print (X[E])
The output of that is:
[ 5 6 7 8 9 10 11]
[1 2 3 4 5 6 7 8 9]
[ 1 2 3 4 5 6 7 8 9 10 11]
[5 6 7 8 9]
[ 1 2 3 4 10 11]
Because you didn't specify what you wanted in the original question), I've also added the opposite operation (to get values not in that range). That's indicated by the E code.
X>4 gives you everything higher than four, (X > 4) | (X < 10) gives you everything that matches that expression, which is everything that matches one or both of the subexpressions, which (in this case) is everything. You could also consider | being set union if you wish, it'll have the same result.