这里给出一维和二维数组的实例,至于三维及更高维的就自行脑补了
一维:
import numpy as np a = np.array([1, 2, 3]) print(a.shape) ----->(3,) b = a[None] print(b.shape) ----->(1, 3) c = a[:, None] print(c.shape) ----->(3, 1)
二维:
import numpy as np d = np.array([[1, 2, 3], [1, 2, 3]]) print(d.shape) ----->(2, 3) e = d[:, :, None] print(e.shape) ----->(2, 3, 1) f = d[:, None, :] print(f.shape) ----->(2, 1, 3)
总结:None所在的位置就是需要升维的位置。