函数原型
numpy.expand_dims(a, axis)
函数说明
expand_dims函数用于在指定维度上进行扩充。
函数使用
# 第一种扩充维度的方法
>>> a = np.ones((4, 2))
>>> a.shape
(4, 2)
>>> b = np.expand_dims(a, axis=1)
>>> b.shape
(4, 1, 2)
# 第二种扩充维度的方法
>>> c = a[:, np.newaxis, :]
>>> c.shape
(4, 1, 2)
# 第三种扩充维度的方法
>>> d = a[:, None, :]
>>> d.shape
(4, 1, 2)