Bird
0
0

Which of the following is the correct syntax to select elements equal to 5 from a numpy array arr using boolean indexing?

easy📝 Syntax Q3 of 15
NumPy - Indexing and Slicing
Which of the following is the correct syntax to select elements equal to 5 from a numpy array arr using boolean indexing?
Aarr[arr === 5]
Barr[arr = 5]
Carr[arr == 5]
Darr[arr != 5]
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct equality operator in numpy

    Use double equals == for comparison, not single = or triple ===.
  2. Step 2: Check options for correct syntax

    Only arr[arr == 5] uses arr[arr == 5], which is correct syntax.
  3. Final Answer:

    arr[arr == 5] -> Option C
  4. Quick Check:

    Equality check uses == in boolean indexing [OK]
Quick Trick: Use == for equality in boolean indexing [OK]
Common Mistakes:
  • Using single = instead of ==
  • Using === which is invalid in Python
  • Using != which means not equal

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes