0

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.

asked Apr 21, 2020 at 19:51
2
  • You need a double equal sign for comparisons == Commented 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!! Commented Apr 29, 2020 at 23:26

1 Answer 1

1

You need a double equal sign for comparisons.

if N[i] == (i-1)/2:
answered Apr 21, 2020 at 19:55
Sign up to request clarification or add additional context in comments.

1 Comment

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!!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.