Google News
logo
NumPy - Interview Questions
How to extract all numbers between a given range from a NumPy array?
a = np.arange(15)
 
Method 1 :
index = np.where((a >= 5) & (a <= 10))
a[index]
 
Method 2 :
index = np.where(np.logical_and(a>=5, a<=10))
a[index]
# (array([6, 9, 10]),)
 
Method 3 : 
a[(a >= 5) & (a <= 10)]

 

Advertisement