0 votes
in Python by
explain numpy.dstack() in Python

1 Answer

0 votes
by

numpy.dstack() in Python

The numpy.dstack() function stacks the arrays in sequence depth wise (along third axis).

Syntax

numpy.dstack(tup)

Parameter

tup: This parameter represents the sequence of arrays where the arrays must have the same shape along all except the third axis.

Return

This function returns the array formed by stacking the given arrays, will be at least 3-D.

Example 1

# Python program explaining
# numpy.dstack() function
import numpy as np
inp_array1 = np.array([[ 11, 12, 13], [ -11, -12, -13]] )
print ("Input array: ", inp_array1) 
inp_array2 = np.array([[ 14, 15, 16], [ -14, -15, -16]] )
print ("Input array: ", inp_array2) 
#stack arrays depth wise (along third axis)
out_array = np.dstack((inp_array1, inp_array2))
print ("Output array: ", out_array)

Output

Input array:  [[ 11  12  13]
[-11 -12 -13]]
Input array:  [[ 14  15  16]
[-14 -15 -16]]
Output array:  [[[ 11  14]
[ 12  15]
[ 13  16]]
[[-11 -14]
[-12 -15]
[-13 -16]]]

Related questions

0 votes
asked May 19, 2022 in Python by john ganales
0 votes
asked May 19, 2022 in Python by john ganales
...