Question: Problem 3: Suppose we a vector u of shape (2,). a matrix X, of which the shape is (n,2), in which we have n rows,

Problem 3: Suppose we a vector u of shape (2,). a matrix X, of which the shape is (n,2), in which we have n rows, and each row represent a point. Write a function nearestneighbor(u,X) that returns the point(s) in X that is closest to u , you may have multiple points. For example: u = np.array([1, 0]) X = np.array([[0, 0],[1, 0],[0, 1]]) nearestneighbor(u,X) should return array([1,0]). Possible tools to use: np.sort, np.argsort, the distance function you have implemented in the graded Lab 2, problem 2 above to check if two floats are the same
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
