Premium problem21. Closest Value to a Scalar

Medium Locked

Return the element of vector that is closest to scalar in absolute difference. If there is a tie, return the first such element in vector.

Input

vector = tensor([10.,  7.,  2.])
scalar = 8.0

Output

tensor(7.)

Premium problem

This one's part of Premium. Unlock the full PyTorch track plus every other premium problem on the site.

Implement solve(...)