Closest Value

easynumpy_indexing

Implement closest_value(x, v).

Given a 1D array x and a scalar v, return the element of x closest to v (the one minimizing |x - v|). No for/while loops.

Constraints
  • no scipy, sklearn
  • no for/while loops

Your solution

Edit closest_value and run the real pytest suite in your browser — no install required. Your code is saved locally.

⌘/Ctrl + ↵

Loading the Python runtime (first run only)…

Hints

Hint 1

a.argmin() gives the index of the min element.