np和cm的复杂2d矩阵上的函数迭代

时间:2019-04-27 13:35:28

标签: python python-3.x

如何使用fct迭代2D矩阵?

在伪代码中,它应如下所示:

import cmath as cm
matrixphase = 0
complexmatrix = fouriertransformation of an image

for each entry:
    matrixphase[i,j]= cm.phase(complexmatrix[i,j])
print(matrix phase)

我认为有一个非常简单的解决方案,但是我只是不知道解决方法。

1 个答案:

答案 0 :(得分:0)

您的问题没有提及名为source的列表, 但是想象一下我们有一个。 然后,C程序员可能会使用嵌套的ij for循环, 而pythonista倾向于支持enumerate

for i, row in enumerate(source):
    for j, item in enumerate(row):
        ...

如果您要显示项目或计算简单金额, 因此不需要索引 那么就足够了:

for row in source:
    for item in row:
        ...