Python | Numpy.dsplit () method



With the Numpy.dsplit()() method we can get the separated dimensions of an array using Numpy.dsplit () () .

Syntax: Numpy.dsplit (numpy.array (), split_size)

Return: Return the array having splitted dimensions.

Example # 1:

In this example, we see that using Numpy.expand_dims () , we can get the split dimensions using this method.

# NumPy import

import numpy as np

 
# using the Numpy.dsplit () method

gfg = np.array ([[ 1 , 2 , 5 ],

[ 3 , 4 , 10 ],

[ 5 , 6 , 15 ],

[ 7 , 8 , 20 ]])

 

gfg = gfg.reshape ( 1 , 2 , 6 )

print (gfg)

 

gfg = np. dsplit (gfg, 2 )

print (gfg)

Logout:

[[[1 2 5 3 4 10]
[5 6 15 7 8 20]]]

[array ([[[1, 2, 5],
[5, 6, 15]]]),
array ([[[3, 4, 10],
[7, 8, 20]]])]

Example # 2:

# NumPy import

import numpy as np

 
# using the Numpy.expand_dims () method

gfg = np.array ([[ 1 , 2 ], [ 7 , 8 ], [ 5 , 10 ]])

gfg = gfg.reshape ( 1 , 2 , 3 )

prin t (gfg)

 

gfg = np.dsplit (gfg, 3 )

print (gfg)

Output:

[[[1 2 7]
[8 5 10]]]

[array ([[[1],
[8]]]), array ([[[2],
[5]]]), array ([[[7],
[10]]])]