where
where finds positions or picks between two values by a condition.
Example
a = np.array([4, -1, 7, -3])
print(np.where(a < 0))
print(np.where(a < 0, 0, a))
print(np.nonzero(a > 3)[0])Result
(array([1, 3]),) [4 0 7 0] [0 2]
Exercise
Choose by condition.
np.(a > 0, 1, 0)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.