作用
扩展数组的形状
插入一个新轴,该轴将出现在扩展数组形状的轴位置上
举例使用
(1)一维数组举例
x = np.array([1, 2])
x.shape
(2,)
y = np.expand_dims(x, axis=0)
y.shape
(1, 2)
y = np.expand_dims(x, axis=1)
y.shape
(2, 1)
(2)二维数组举例
x = np.array([[1,2,3],[4,5,6]])
x.shape
(2, 3)
y = np.expand_dims(x,axis=0)
y.shape
(1, 2, 3)
y = np.expand_dims(x,axis=1)
y.shape
(2, 1, 3)
y = np.expand_dims(x,axis=2)
y.shape
(2, 3, 1)