I recently read some source code from the sklearn BallTree class , which is written in Cython, and I came across some fancy syntax in a for loop:
for j from 0 <= j < n_features:
centroid[j] += this_pt[j]
After some inspection, I can’t find the documentation for using the keyword fromin a loop for. In fact, this answer clearly indicates that the only use fromin Python is in a sentence import_from.
Although it reads strangely, my interpretation of the string is essentially:
for j in range(n_features):
...
... that adheres to the condition that jbegins with 0and remains smaller n_features. What exactly is the advantage of weird syntax, and does it do something different than what I expect?
source
share