Python| Numpy.expand_dims() 方法
借助Numpy.expand_dims()
方法,我们可以使用Numpy.expand_dims()
方法获得数组的扩展维度。
Syntax : Numpy.expand_dims()
Return : Return the expanded array.
示例 #1:
在这个例子中我们可以看到使用Numpy.expand_dims()
方法,我们可以使用这个方法得到扩展数组。
# 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)
输出 :
(2, )
(1, 2)
示例 #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)
输出 :
(2, 2)
(1, 2, 2)