Bird
0
0

Given a 6x6 NumPy array grid, which slicing extracts the central 4x4 sub-array?

hard📝 Application Q8 of 15
NumPy - Indexing and Slicing
Given a 6x6 NumPy array grid, which slicing extracts the central 4x4 sub-array?
Agrid[1:4, 1:4]
Bgrid[2:6, 2:6]
Cgrid[1:5, 1:5]
Dgrid[0:4, 0:4]
Step-by-Step Solution
Solution:
  1. Step 1: Understand array dimensions

    The array is 6x6, indices run from 0 to 5.
  2. Step 2: Identify central 4x4 block

    The central 4x4 block excludes the outermost rows and columns, so rows 1 to 4 and columns 1 to 4.
  3. Step 3: Write slicing notation

    Since slicing excludes the end index, use grid[1:5, 1:5] to include rows and columns 1,2,3,4.
  4. Final Answer:

    grid[1:5, 1:5] -> Option C
  5. Quick Check:

    Check shape of slice is (4,4) [OK]
Quick Trick: Central slice excludes outermost rows and columns [OK]
Common Mistakes:
  • Using incorrect end index in slicing
  • Confusing inclusive and exclusive slicing bounds
  • Selecting wrong rows or columns for center

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes