Bird
0
0

You have a 4x4 numpy array arr filled with numbers 1 to 16 in row-major order. Which code correctly changes the element in the last row and second column to 100?

hard📝 Application Q15 of 15
NumPy - Indexing and Slicing
You have a 4x4 numpy array arr filled with numbers 1 to 16 in row-major order. Which code correctly changes the element in the last row and second column to 100?
Aarr[3, -2] = 100
Barr[4, 2] = 100
Carr[-1, 2] = 100
Darr[3, 1] = 100
Step-by-Step Solution
Solution:
  1. Step 1: Identify last row and second column indexes

    For a 4x4 array, rows and columns are indexed 0 to 3. Last row is index 3, second column is index 1.
  2. Step 2: Check each option

    arr[3, 1] = 100 uses arr[3, 1] which is correct. arr[4, 2] = 100 uses invalid index 4. arr[-1, 2] = 100 uses column index 2 (third column), not second. arr[3, -2] = 100 uses negative index -2 for column which is the third column, not second.
  3. Final Answer:

    arr[3, 1] = 100 -> Option D
  4. Quick Check:

    Last row = 3, second column = 1 [OK]
Quick Trick: Use zero-based indexes: last row is size-1, second column is 1 [OK]
Common Mistakes:
  • Using out-of-range indexes like 4
  • Confusing negative indexes for columns
  • Mixing row and column positions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes