Bird
0
0

What is the main difference between np.vstack() and np.hstack() when combining arrays?

easy📝 Conceptual Q1 of 15
NumPy - Array Manipulation
What is the main difference between np.vstack() and np.hstack() when combining arrays?
ABoth stack arrays vertically but differ in input types.
B<code>np.vstack()</code> stacks arrays horizontally, <code>np.hstack()</code> stacks vertically.
CBoth stack arrays horizontally but differ in input types.
D<code>np.vstack()</code> stacks arrays vertically (row-wise), <code>np.hstack()</code> stacks horizontally (column-wise).
Step-by-Step Solution
Solution:
  1. Step 1: Understand stacking directions

    np.vstack() stacks arrays by adding rows, increasing the number of rows.
  2. Step 2: Compare with np.hstack()

    np.hstack() stacks arrays by adding columns, increasing the number of columns.
  3. Final Answer:

    np.vstack() stacks vertically, np.hstack() stacks horizontally. -> Option D
  4. Quick Check:

    Stacking direction = Vertical vs Horizontal [OK]
Quick Trick: Vertical adds rows, horizontal adds columns [OK]
Common Mistakes:
  • Confusing vertical with horizontal stacking
  • Assuming both functions do the same stacking
  • Mixing up input array shapes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes