0
点赞
收藏
分享

微信扫一扫

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

深夜瞎琢磨 2022-05-04 阅读 37
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 条评论