Looking for a more efficient way to check if items within a numpy array fall within any (or match at least once) of a set of min & max values. I toyed around with any() and np.any() and all() but these are newer concepts to me.
y_minmax_bounds = [[1.1, 2.0], [3.3, 6.21], [5.75, 10.0]]
y = np.array([1.5, 2.5, 2, 6, 8, 10])
withinbounds = [((y > min) & (y < max))for min, max in y_minmax_bounds]
print(withinbounds)
Returns:
[array([True, False, False, False, False, False]),
array([False, False, False, True, False, False]),
array([False, False, False, True, True, False])]
After a array solution of:
[True False False True True False]
I can loop over y_minmax_bounds, but this seems inefficient given a very large np.array to check. The actual problem will also be enforcing this in multiple dimensions (x_minmax_bounds on x, z_minmax_bounds over z).
y_minmax_bounds, which also sets 2.5 and 2 as False.