Bird
0
0

If you have two arrays a = np.array([1, 2]) and b = np.array([3, 4]), what will np.hstack((a, b)) produce?

easy📝 Conceptual Q2 of 15
NumPy - Array Manipulation
If you have two arrays a = np.array([1, 2]) and b = np.array([3, 4]), what will np.hstack((a, b)) produce?
Aarray([[1, 2], [3, 4]])
Barray([[1, 3], [2, 4]])
Carray([1, 2, 3, 4])
Darray([[1], [2], [3], [4]])
Step-by-Step Solution
Solution:
  1. Step 1: Check input arrays shape

    Both a and b are 1D arrays with shape (2,).
  2. Step 2: Apply np.hstack() on 1D arrays

    np.hstack() concatenates them into a longer 1D array: [1, 2, 3, 4].
  3. Final Answer:

    array([1, 2, 3, 4]) -> Option C
  4. Quick Check:

    1D arrays horizontal stack = 1D concatenation [OK]
Quick Trick: hstack joins arrays side-by-side in 1D as flat array [OK]
Common Mistakes:
  • Expecting a 2D array output
  • Confusing hstack with vstack for 1D arrays
  • Misreading array shapes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes