np.newaxis的作用是对已有数据增加一个维度:
x = np.random.randint(1, 8, size=5)
x.shape
(5,) #原始唯独
x1 = x[np.newaxis, :]
x1.shape
(1, 5) #维度变为(1,5)
x1
array([[1, 6, 6, 3, 2]])
x2 = x[:, np.newaxis]
x2.shape
(5, 1) #维度变为(5,1)
x2
array([[1],
[6],
[6],
[3],
[2]])