Bird
0
0

Which of the following is the correct syntax to select all rows and columns 2 to 4 (inclusive start, exclusive end) from a NumPy array named arr?

easy📝 Syntax Q12 of 15
NumPy - Indexing and Slicing
Which of the following is the correct syntax to select all rows and columns 2 to 4 (inclusive start, exclusive end) from a NumPy array named arr?
A<code>arr[2:4, :]</code>
B<code>arr[:, 2:5]</code>
C<code>arr[2:5, :]</code>
D<code>arr[:, 2:4]</code>
Step-by-Step Solution
Solution:
  1. Step 1: Identify rows and columns in slicing

    The first index before comma is rows, second is columns.
  2. Step 2: Select all rows and columns 2 to 4

    All rows means :, columns 2 to 4 means 2:5 because end is excluded.
  3. Final Answer:

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

    All rows = :, columns 2 to 4 = 2:5 [OK]
Quick Trick: Use ':' for all rows or columns [OK]
Common Mistakes:
  • Swapping rows and columns in slicing
  • Using wrong end index in slice
  • Missing colon for all rows or columns

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes