import numpy as np
a = np.random.random((5,6,9))
# 第一种
b = a[:,2,None,:]
print(b.shape)
# 第二种
c = a[:,2,np.newaxis,:]
print(c.shape)
# D:\Anaconda3\python.exe "D://01.py"
# (5, 1, 9)
# (5, 1, 9)
#
# Process finished with exit code 0
微信扫一扫
import numpy as np
a = np.random.random((5,6,9))
# 第一种
b = a[:,2,None,:]
print(b.shape)
# 第二种
c = a[:,2,np.newaxis,:]
print(c.shape)
# D:\Anaconda3\python.exe "D://01.py"
# (5, 1, 9)
# (5, 1, 9)
#
# Process finished with exit code 0
相关推荐