Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q5 of 15
NumPy - Array Manipulation
What will be the output of this code?
import numpy as np
x = np.array([1, 2, 3])
y = np.array([4, 5, 6])
result = np.concatenate((x, y), axis=0)
print(result)
A[1 2 3]
B[1 2 3 4 5 6]
C[[1 2 3] [4 5 6]]
DError due to axis parameter
Step-by-Step Solution
Solution:
  1. Step 1: Check array shapes

    x and y are 1D arrays of shape (3,). Concatenating along axis=0 joins them end to end.
  2. Step 2: Concatenate arrays

    Result is a 1D array with elements from x followed by y.
  3. Final Answer:

    [1 2 3 4 5 6] -> Option B
  4. Quick Check:

    Concatenate 1D arrays joins elements [OK]
Quick Trick: Concatenate 1D arrays joins elements end-to-end [OK]
Common Mistakes:
  • Expecting 2D array output
  • Thinking axis=0 causes error for 1D arrays
  • Confusing concatenate with stack

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes