Thursday, December 26, 2024
Google search engine
HomeLanguagesPython | Numpy.expand_dims() method

Python | Numpy.expand_dims() method

With the help of Numpy.expand_dims() method, we can get the expanded dimensions of an array by using Numpy.expand_dims() method.

Syntax : Numpy.expand_dims()

Return : Return the expanded array.

Example #1 :
In this example we can see that using Numpy.expand_dims() method, we are able to get the expanded array using this method.




# import numpy
import numpy as np
  
# using Numpy.expand_dims() method
gfg = np.array([1, 2])
print(gfg.shape)
  
gfg = np.expand_dims(gfg, axis = 0)
print(gfg.shape)


Output :

(2, )
(1, 2)

Example #2 :




# import numpy
import numpy as np
  
# using Numpy.expand_dims() method
gfg = np.array([[1, 2], [7, 8]])
print(gfg.shape)
  
gfg = np.expand_dims(gfg, axis = 0)
print(gfg.shape)


Output :

(2, 2)
(1, 2, 2)

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments