NumPy TutorialLesson 16Free preview
NumPy Array Filter
This lesson is part of NumPy · All levels
Summary
Array filtering uses boolean indexing, which is to place conditions such as arr > 10 in square brackets. The result contains only qualifying elements, so it replaces the if repetition manually. You can also use np.where or even create a filter pattern to generate new values.
Key points
- Boolean indexing arr[condition] filters the elements according to the condition.
- The condition can be combined with & (and) or ̊ (or), not and/or.
- Np.where gives the position or value of the result of the selection.
- A particular (divisible) pattern can be made from an element filter.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.