I don't know how to improve the error code. SyntaxError: invalid character identifier

Asked 2 years ago, Updated 2 years ago, 51 views

I get an error when I execute the code below, but I don't know where to improve it.

Dis_sample=[]
for_in range(10):
    PP=np.random.choice (P_sample_all.shape[0], 2, replace=False)
    PP_sample.append(PP)
   
  Dis=np.sqrt((P_sample_all [PP[0],0]-P_sample_all [PP[1],0])**2+
                (P_sample_all[PP[0],1]-P_sample_all[PP[1],1])**2+
                (P_sample_all[PP[0],2]-P_sample_all[PP[1],2])**2)
    Dis_sample.append(Dis)

This is the error.

Dis=np.sqrt(P_sample_all[PP[0],0]-P_sample_all[PP[1],0])**2+
   ^   
SyntaxError: invalid character identifier

Additional
If you run the error part outside of the for statement, it works.

python numpy

2022-09-30 16:49

2 Answers

Full-width spaces are used to indent the line.
Please correct it to a half-width blank.

Comment ready:

Come to think of it, the blank line right before the error line is three half-width blank, which seems to be different from other lines, but will that affect you?Try arranging it.


2022-09-30 16:49

The problem was that the line feed created a connection with the previous sentence, and the part that defined Dis was not reflected in the variable definition.

Improved by erasing blank lines between previous sentences.After that, the error no longer appears when I try to break the line again.


2022-09-30 16:49

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.