Bird
0
0

Which slicing selects the first three rows and all columns from a 2D NumPy array?

easy📝 Conceptual Q2 of 15
NumPy - Indexing and Slicing
Which slicing selects the first three rows and all columns from a 2D NumPy array?
Aarray[:, 0:3]
Barray[0:3, :]
Carray[3, :]
Darray[:3, 3]
Step-by-Step Solution
Solution:
  1. Step 1: Interpret the slice for rows

    0:3 means rows from index 0 up to but not including 3, so first three rows.
  2. Step 2: Interpret the slice for columns

    : means all columns are selected.
  3. Final Answer:

    array[0:3, :] selects first three rows and all columns -> Option B
  4. Quick Check:

    Rows 0 to 2, all columns = array[0:3, :] [OK]
Quick Trick: Use start:stop for rows, colon for all columns [OK]
Common Mistakes:
  • Swapping rows and columns in slicing
  • Using single index instead of slice
  • Using wrong stop index

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes