I have a big numpy array with certain entries. Let's say a dummy example is:
arr = np.array([[[1.0, 2.0, 3.0],[1.5, 1.8, 3.2]],
[[1.3, 1.7, 1.9],[1.4, 1.9, 2.1]],
[[1.8, 2.2, 2.5],[2.0, 2.2, 2.8]]])
I would like to know all the indexes where the entries of arr fall within some range, say 1.5 and 2.4. And I would like to fill another matrix of the same shape as arr with 1 at indexes where value of arr falls within the range, otherwise with 0. That is, I would like to get a matrix like:
mask = np.array([[[0, 1, 0], [1, 1, 0]],
[[0, 1, 1], [0, 1, 1]],
[[1, 1, 0], [1, 1, 0]]])
Is there any simple numpy trick to do this? I know it is straightforward to do it with a for loop, but since my arr is pretty big in size, I would want it to be reasonably fast. Thanks