How to use multiple conditional expressions to select values from a NUMPY array?

Viewed 32
b = np.array([2,3,4,5])
b[b>=1] 

we can get the values which are greater than 1 in b.

However

b = np.array([2,3,4,5])
b[b>=1 and b <= 2] 

will raise ValueError.

How can i fix this problem?

1 Answers
b = np.array([2,3,4,5])
b[(b>=1) & ( b <= 2)] 
Related