The dstack()
function in NumPy is used to stack or arrange the given arrays in a sequence depth wise (that is, along the third axis), thereby creating an array of at least 3-D
.
dstack()
function worksnumpy.dstack(tup)
The dstack()
function takes the parameter value, tup
, which represents a sequence of arrays having the same shape along all the axes except for the third axis.
The dstack()
function returns an array of at least 3-D
by stacking the input arrays.
import numpy as np# creating input arraysa = np.array([1, 2, 3, 4, 5])b = np.array([6, 7, 8, 9, 10])# stacking the arrays sequential depth wisestacked_array = np.dstack((a, b))# printing the new arrayprint(stacked_array)
numpy
module.a
and b
using the array()
function.a
and b
using the dstack()
function. Then, we assign the result to a variable called stacked_array
.stacked_array
array.