FunctionRacerProblemsRace

Closest to Origin

EasyNumPyPython

points is a 2-D array with one point per row, as [x, y]. Return the row number of the point closest to the origin (0, 0). If two points are equally close, return the smaller row number. Hint: you can compare x * x + y * y instead of taking square roots.

Example 1

points [[3,4],[1,1],[-2,0]]
returns 1

The distances are 5, about 1.41 and 2, so row 1.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More NumPy problems