Bird
0
0

Which of the following is the correct syntax to join two 1D arrays a and b using np.concatenate()?

easy📝 Syntax Q12 of 15
NumPy - Array Manipulation
Which of the following is the correct syntax to join two 1D arrays a and b using np.concatenate()?
Anp.concatenate([a, b])
Bnp.concatenate(a, axis=1)
Cnp.concatenate(a + b)
Dnp.concatenate(a, b)
Step-by-Step Solution
Solution:
  1. Step 1: Check the function signature

    np.concatenate() expects a single argument: a sequence (like a list or tuple) of arrays to join.
  2. Step 2: Analyze each option

    np.concatenate([a, b]) correctly passes a list of arrays [a, b]. np.concatenate(a, b) passes two separate arguments, which is invalid. np.concatenate(a + b) tries to add arrays before concatenation, which is not the function's purpose. np.concatenate(a, axis=1) passes axis=1 for 1D arrays, which is invalid.
  3. Final Answer:

    np.concatenate([a, b]) -> Option A
  4. Quick Check:

    Pass arrays as a list to concatenate() [OK]
Quick Trick: Always pass arrays inside a list or tuple to concatenate [OK]
Common Mistakes:
  • Passing arrays as separate arguments instead of a list
  • Using plus (+) operator instead of concatenate
  • Setting wrong axis for 1D arrays

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes