简体   繁体   中英

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.

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.

You need a double equal sign for comparisons.

if N[i] == (i-1)/2:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM