[英]Creating a for loop within a for loop with an if statement
I am trying to create a for loop within a for loop, with an if statement with the following code where N and r are both columns of float numbers.我正在尝试在 for 循环中创建一个 for 循环,使用带有以下代码的 if 语句,其中 N 和 r 都是浮点数列。
x = math.floor(max(N)*2)
x_1 = np.zeros((x,1),dtype=np.int16)
for i in range (1,x):
for j in range (1, max(N)):
if N[i] = (i-1)/2:
x_1[i] = max(x_1[j], r[i])
The error I am getting here is invalid syntax for the line: if N[i] = (i-1)/2:
Specifically under the equals sign.我在这里遇到的错误是该行的无效语法:
if N[i] = (i-1)/2:
特别是在等号下。
You need a double equal sign for comparisons.您需要一个双等号进行比较。
if N[i] == (i-1)/2:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.