Bird
0
0

Given a NumPy array arr = np.array([10, 20, 30, 40, 50]), which indexing method will create a new array with only elements greater than 25?

hard📝 Application Q9 of 15
NumPy - Indexing and Slicing
Given a NumPy array arr = np.array([10, 20, 30, 40, 50]), which indexing method will create a new array with only elements greater than 25?
Aarr[:25]
Barr[arr > 25]
Carr[2:4]
Darr[25:]
Step-by-Step Solution
Solution:
  1. Step 1: Understand boolean indexing

    arr > 25 creates a boolean mask selecting elements greater than 25.
  2. Step 2: Apply boolean mask to array

    arr[arr > 25] returns elements 30, 40, 50 as a new array.
  3. Final Answer:

    arr[arr > 25] -> Option B
  4. Quick Check:

    Boolean indexing filters elements by condition [OK]
Quick Trick: Use boolean masks inside brackets to filter arrays [OK]
Common Mistakes:
  • Using slice with value instead of index
  • Confusing slicing with condition
  • Expecting arr[25:] to filter values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes