Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q5 of 15
NumPy - Indexing and Slicing
What will be the output of this code?
import numpy as np
arr = np.array([10, 15, 20, 25])
filtered = arr[(arr % 20) == 0]
A[15 25]
B[10 20]
C[]
D[20]
Step-by-Step Solution
Solution:
  1. Step 1: Calculate arr % 20 for each element

    Results: 10%20=10, 15%20=15, 20%20=0, 25%20=5.
  2. Step 2: Select elements where remainder is 0

    Only 20 satisfies (arr % 20) == 0.
  3. Final Answer:

    [20] -> Option D
  4. Quick Check:

    Modulo zero elements = [20] [OK]
Quick Trick: Use modulo in boolean indexing to filter multiples [OK]
Common Mistakes:
  • Selecting elements with non-zero remainder
  • Misunderstanding modulo operation
  • Including all elements by mistake

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes