Compute the Euclidean distance between two equal-length vectors:
d(x,y)=i=1∑N(xi−yi)2Here, N is the vector length and xi and yi are corresponding coordinates. Return the distance as a Python float.
Input: x = [3, 4], y = [0, 0]
Output: 5.0
Explanation: The squared differences are 9 and 16, so the distance is the square root of 25.
Input: x = [1, 2, 3], y = [4, 5, 6]
Output: 5.196152
Input: x = [0, 0, 0], y = [0, 0, 0]
Output: 0.0
difference = np.asarray(x, dtype=float) - np.asarray(y, dtype=float) forms the displacement vector.
np.sqrt(np.sum(difference ** 2)) computes its L2 norm.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Compute the Euclidean distance between two equal-length vectors:
d(x,y)=i=1∑N(xi−yi)2Here, N is the vector length and xi and yi are corresponding coordinates. Return the distance as a Python float.
Input: x = [3, 4], y = [0, 0]
Output: 5.0
Explanation: The squared differences are 9 and 16, so the distance is the square root of 25.
Input: x = [1, 2, 3], y = [4, 5, 6]
Output: 5.196152
Input: x = [0, 0, 0], y = [0, 0, 0]
Output: 0.0
difference = np.asarray(x, dtype=float) - np.asarray(y, dtype=float) forms the displacement vector.
np.sqrt(np.sum(difference ** 2)) computes its L2 norm.
Sign in to take notes on this problem
Accepts: array
Accepts: array