Bird
0
0

Find the mistake in this code:

medium📝 Debug Q7 of 15
NumPy - Array Manipulation
Find the mistake in this code:
import numpy as np
arr = np.array([[[1], [2], [3]]])
squeezed = np.squeeze(arr, axis=1)
AAxis 1 cannot be squeezed because its size is not 1
Bnp.squeeze() does not accept axis parameter
Carr is not a NumPy array
DNo mistake, code runs correctly
Step-by-Step Solution
Solution:
  1. Step 1: Check shape of arr

    arr shape is (1, 3, 1), axis 1 has size 3.
  2. Step 2: Validate axis parameter for squeeze

    Only axes with size 1 can be squeezed. Axis 1 size 3 cannot be squeezed.
  3. Final Answer:

    Axis 1 cannot be squeezed because its size is not 1 -> Option A
  4. Quick Check:

    Only size 1 axes can be squeezed [OK]
Quick Trick: Squeeze axis must have size 1 [OK]
Common Mistakes:
  • Trying to squeeze non-size 1 axis
  • Ignoring axis parameter rules
  • Assuming squeeze always works

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes