np.newaxis:为数组多加一个轴,np.newaxis在哪里,多加的轴就在那里
import numpy as np
a = np.array([[[0,1,2],[3,4,5],[6,7,8]],
[[1,2,2],[2,2,2],[2,2,2]]])
print(a.shape) #(2, 3, 3)
b=a[:,:,:,np.newaxis]
print(b.shape)#(2, 3, 3, 1)
c=a[:,:,np.newaxis,:]
print(c.shape) #(2, 3, 1, 3)
d=a[:,np.newaxis,:,:]
print(d.shape) #(2, 1, 3, 3)
e=a[np.newaxis,:,:,:]
print(e.shape) #(1, 2, 3, 3)
f=a[np.newaxis]
print(f.shape)#(1, 2, 3, 3)