Question: What's wrong with my code? Can you have a better idea? Exercise: Euclidean distance (2 points) Recall that the Euclidean distance d is given by

 What's wrong with my code? Can you have a better idea?Exercise: Euclidean distance (2 points) Recall that the Euclidean distance d is

What's wrong with my code? Can you have a better idea?

Exercise: Euclidean distance (2 points) Recall that the Euclidean distance d is given by the following equation: N da, b) = WE b;) i=1 In NumPy, this is a fairly simple computation because we can rely on array computations and the np. sum function to do all the heavy lifting for us. Complete the function euclidean_distance below to compute d(a,b), as given by the equation above. Note that you can compute the square root using np. sqrt. : def euclidean_distance (a, b) : "*" "Computes the Euclidean distance between a and b. Hint: your solution can be done in a single line of code! Parameters a, b: numpy arrays or scalars with the same size Returns the Euclidean distance between a and b # YOUR CODE HERE raise Not ImplementedError() Problem 1 Show that for a=[0 3 0] and b=[4 0 0], the euclidean distance is 5. In [17]: import numpy as np def euclidean_distance (a, b): D = 0 for i in range (len(a)): D += np. sum(a[i] = b[i]) ** 2 D = np. sqrt (D) return D print (euclidean_distance (CO 3 0], [4 0 0])) File "/tmp/ipykernel_61/614150627.py", line 10 euclidean_distance ([0 3 0], [4 0 0]) SyntaxError: invalid syntax

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!