多为数组索引保持维度不变

阅读 41

2022-05-04

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

 

相关推荐

精彩评论(0)

0 0 举报