Curriculum
Course: NumPy
Login

Curriculum

NumPy

Text lesson

Joining Arrays Using Stack Functions

Stacking is similar to concatenation, with the main distinction being that stacking occurs along a new axis.

When concatenating two 1-D arrays along the second axis, the result is that they are stacked on top of each other.

To perform stacking, we provide a sequence of arrays to the stack() method along with the specified axis. If the axis is not explicitly defined, it defaults to 0.

Example

import numpy as np

arr1 = np.array([123])

arr2 = np.array([456])

arr = np.stack((arr1, arr2), axis=1)

print(arr)