np.where(arr == 4)returns the indexes of matches.np.sort(arr)returns a sorted copy.- Boolean indexing:
arr[arr > 50]keeps the elements where the condition is True.
NumPy Search, Sort & Filter
where, sort and boolean masks.
✍️ 3 exercises + code challenge in this lessonKey Takeaways: NumPy Search, Sort & Filter
Mastering NumPy Search, Sort & Filter helps you write clean and reliable NumPy code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
NumPy Search, Sort & Filter Code Example
NumPyimport numpy as np
marks = np.array([72, 95, 58, 88, 64])
print(np.sort(marks))
print(np.where(marks == 88))
print(marks[marks >= 70])
print((marks >= 70).sum(), "students passed")
Output
[58 64 72 88 95] (array([3]),) [72 95 88] 3 students passed
Free sign-in required · Google login available
NumPy Search, Sort & Filter Practice Exercises
Check what you learned in “NumPy Search, Sort & Filter”.
/ 3 solved
Fill in the blank
Keep only values greater than 50.
big = arr[arr 50]
✓ Correct!
Not quite. Try again.
Multiple choice
What does np.sort(arr) return?
✓ Correct!
Not quite. Try again.
Code challenge
Print the even numbers of arr as a list using a boolean filter.
Write the code in the live editor. Your answer is checked automatically.
✓ Solved
Free sign-in required · Google login available
to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.
Stuck on something?
Ask the community in the CodesInTech forum.
Need a developer?
Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.
Explore Our Services