Python | Numpy dstack () method

With the numpy.dstack() method we can get the index of the merged array by index and store as a stack using numpy.dstack () .

Syntax: numpy.dstack ((array1, array2))

Return: Return combined array index by index.

Example # 1:
In this example, we can see that with numpy .dstack () we can get the merged array as a stack index by index.

# NumPy import

import numpy as np

 

gfg1 = np.array ([ 1 , 2 , 3 ])

gfg2 = np.array ([ 4 , 5 , 6 ])

 
# using the numpy.dstack () method

print ( np.dstack ((gfg1, gfg2)))

Output:

[[[1 4]
[2 5]
[3 6]]]

Example # 2:

# NumPy import

import numpy as np  

 

gfg1 = np.array ([[ 10 ], [ 2 ], [ 13 ]] )

gfg2 = np.array ( [[ 41 ], [ 55 ], [ 6 ]])

 
# using the numpy.dstack () method

print (np.dstack ((gfg1, gfg2)))

Logout:

[[[10 41]]

[[2 55] ]

[[13 6]]]