-1

The following code was constructed to be an efficent method of finding the the closest pairs for two elements in a list:

idx = np.searchsorted(xx, yy, side="left").clip(max=xx.size-1)
mask = (idx > 0) &  \
       ( (idx == len(xx)) | (np.fabs(yy - xx[idx-1]) < np.fabs(yy - xx[idx])) )
out = xx[idx-mask]

I have a simple question: What is the backslash doing in this code? I've tried googling and trying different codes to figure it out myself without success, for example:

enter image description here

Here I see that it doesn't seem like the backslash is an operator that acts on numpy arrays.

Steven Sagona
  • 115
  • 1
  • 11
  • 3
    Just a line separator. – Divakar Oct 23 '19 at 18:13
  • As the error message says: "line continuation character" , it indicates that the line doesn't end there but goes on on the following line. As this only makes sense at the end of a line, you are getting the error you're getting – Paul Panzer Oct 23 '19 at 18:16
  • Thanks everyone. Seeing the answer, I see that I should've been able to figure it out on my own given the error message. I tried to figure out what the backslash meant instead of just googling the error message. In the future I'll make a better attempt to make sense of the error message first. – Steven Sagona Oct 23 '19 at 19:34

1 Answers1

1

\ is the line continuation character. Non-whitespace characters after this, will trigger a SyntaxError, as you have discovered the hard way.

norok2
  • 25,683
  • 4
  • 73
  • 99