I’m trying to find the indices of all elements in an array that are greater than a but less than b. It’s probably just a problem with my syntax but this doesn’t work:
numpy.where((my_array > a) and (my_array < b))
How should I fix this? Or is there a better way to do it?
Thanks!
Here are two ways:
For the first (replacing
andwith&), be careful to add parentheses appropriately:&has higher precedence than the comparison operators. You can also use*, but I wouldn’t recommend it: it’s hacky and doesn’t make for readable code.