How to Stack NumPy Arrays Along Height (depth)


In this example we will show how to stack NumPy arrays along height (depth) using the dstack() function in Python.

Source Code

import numpy as np

a = np.array([1, 2, 3, 4])
b = np.array([5, 6, 7, 8])

c = np.dstack((a, b))

print(c)

Output:

[[[1 5]
  [2 6]
  [3 7]
  [4 8]]]
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments