Bird
0
0

Which of the following is the correct syntax to select elements at indices 1, 3, and 5 from a NumPy array named arr?

easy📝 Syntax Q3 of 15
NumPy - Indexing and Slicing
Which of the following is the correct syntax to select elements at indices 1, 3, and 5 from a NumPy array named arr?
Aarr(1, 3, 5)
Barr[[1, 3, 5]]
Carr[1:3:5]
Darr{1, 3, 5}
Step-by-Step Solution
Solution:
  1. Step 1: Recall fancy indexing syntax

    To select multiple elements by indices, use double square brackets with a list of indices.
  2. Step 2: Check other options

    Parentheses, slicing with colons, or curly braces are invalid for this purpose.
  3. Final Answer:

    arr[[1, 3, 5]] -> Option B
  4. Quick Check:

    Correct syntax uses double brackets = arr[[indices]] [OK]
Quick Trick: Use double brackets with list of indices for fancy indexing [OK]
Common Mistakes:
  • Using parentheses instead of brackets
  • Using slicing syntax incorrectly
  • Using curly braces which are invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes