Bird
0
0

Find the issue in this code snippet:

medium📝 Debug Q7 of 15
NumPy - Array Manipulation
Find the issue in this code snippet:
import numpy as np
x = np.array([[1, 2], [3, 4]])
y = np.array([5, 6, 7])
result = np.hstack((x, y))
AMissing brackets around arrays in hstack
BShapes of arrays do not match for horizontal stacking
Cnp.hstack cannot stack 1D and 2D arrays
DNo issue, code runs correctly
Step-by-Step Solution
Solution:
  1. Step 1: Check shapes of arrays

    x shape is (2, 2), y shape is (3,).
  2. Step 2: Understand hstack requirements

    For horizontal stacking, arrays must have the same number of rows.
  3. Final Answer:

    Shapes of arrays do not match for horizontal stacking -> Option B
  4. Quick Check:

    Rows must match for hstack [OK]
Quick Trick: hstack needs matching rows, vstack needs matching columns [OK]
Common Mistakes:
  • Ignoring shape mismatch errors
  • Assuming 1D and 2D arrays stack freely
  • Confusing stacking axis

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes