How to use NumPy Joining Array?
Ask by ICSM Computer
Updated 13 Nov 2025
1. Using
np.concatenate()This is the most common way to join arrays.
Example — Join 1D Arrays
Output:
Example — Join 2D Arrays (Row-wise)
Output:
Example — Join 2D Arrays (Column-wise)
Output:
2. Using
np.stack()Creates a new dimension.
Example:
Output:
Here, arrays are stacked into 2 rows.
3. Using
np.hstack()(Horizontal Stack)Joins arrays side by side.
Output:
For 2D arrays, it stacks column-wise.
4. Using
np.vstack()(Vertical Stack)Joins arrays top to bottom.
Output:
5. Using
np.dstack()(Depth Stack)Stacks arrays into depth (3rd dimension).
Output:
Summary Table
concatenate()stack()hstack()vstack()dstack()