NumPy TutorialLesson 14Free preview
NumPy Array Search
This lesson is part of NumPy · All levels
Summary
Searching in NumPy arrays is done with np.where looking for positions based on certain conditions. np.searchsorted looking for insertion indexes so that the array remains sorted, while np.count_nonzero counts non-zero elements. All three allow for quick search without writing manual repetitions.
Key points
- Returns the tuple index that satisfies the condition.
- Working on a sorted array.
- Calculate the elements with values other than zero.
- The joint use of np.where in the if-elif-else condition replaces the branch per element.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.