Bird
0
0

What is the shape of the array after applying np.squeeze() to arr = np.array([[[1], [2], [3]]])?

medium📝 Predict Output Q13 of 15
NumPy - Array Manipulation
What is the shape of the array after applying np.squeeze() to arr = np.array([[[1], [2], [3]]])?
A(3,)
B(1, 3, 1)
C(3, 1)
D(3, 1, 1)
Step-by-Step Solution
Solution:
  1. Step 1: Check original shape

    arr has shape (1, 3, 1) because it is a 3D array with one element in first and last dimension.
  2. Step 2: Apply np.squeeze()

    np.squeeze() removes all dimensions of size 1, so the first and last dimensions are removed, leaving shape (3,).
  3. Final Answer:

    (3,) -> Option A
  4. Quick Check:

    squeeze removes size 1 dims = (3,) [OK]
Quick Trick: Squeeze removes all size 1 dims from shape [OK]
Common Mistakes:
  • Assuming squeeze removes only one dimension
  • Confusing original shape with squeezed shape
  • Thinking squeeze flattens the array

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes