Skip to main content
 首页 » 编程设计

python之如何使用 numpy Python 打印 3D 矩阵中的特定列

2025年05月04日26rubylouvre

我在打印 numpy 3D 矩阵中的列时遇到问题。 这是问题的简化版本:

import numpy as np 
Matrix = np.zeros(((10,9,3))) # Creates a 10 x 9 x 3 3D matrix 
Matrix[2][2][6] = 578 
# I want to print Matrix[2][x][6] for x in range(9) 
# the purpose of this is that I want to get all the Values in Matrix[2][x][6] 

如果你们能帮助我,我将不胜感激。 提前致谢。

请您参考如下方法:

切片会起作用:

a = np.zeros((10, 9, 3)) 
a[6, 2, 2] = 578 
for x in a[6, :, 2]: 
    print(x) 

输出:

0.0 
0.0 
578.0 
0.0 
0.0 
0.0 
0.0 
0.0 
0.0