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 ==user984003– user9840032020年04月21日 19:54:36 +00:00Commented Apr 21, 2020 at 19:54
-
Thanks for the help! I've updated by code with the == signs. It appears to be working, but never converges on an answer (just shows the hourglass that the code is running). I know my N is a numpy array, my x and x_1 are 'int', and my r is a pandas.core.series. Do I need to add anything additional to make this converge faster? Any help is appreciated!!Rachel– Rachel2020年04月29日 23:26:48 +00:00Commented Apr 29, 2020 at 23:26
1 Answer 1
You need a double equal sign for comparisons.
if N[i] == (i-1)/2:
answered Apr 21, 2020 at 19:55
user984003
29.9k69 gold badges205 silver badges320 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Rachel
Thanks for the help! I've updated by code with the == signs. It appears to be working, but never converges on an answer (just shows the hourglass that the code is running). I know my N is a numpy array, my x and x_1 are 'int', and my r is a pandas.core.series. Do I need to add anything additional to make this converge faster? Any help is appreciated!!
lang-py