The Manhattan distance (L1 distance) between two equal-length vectors x, y is:
d(x,y)=i∑∣xi−yi∣Input: x = [1,2,3], y = [2,4,6]
Output: 6.0
|1-2| + |2-4| + |3-6| = 1 + 2 + 3 = 6
Input: x = [-1,-2], y = [1,2]
Output: 6.0
|-1-1| + |-2-2| = 2 + 4 = 6
Input: x = [0,0,0], y = [0,0,0]
Output: 0.0
Convert inputs to NumPy arrays first, then use vectorized operations to compute absolute differences.
Sign in to take notes on this problem
Accepts: array
Accepts: array
The Manhattan distance (L1 distance) between two equal-length vectors x, y is:
d(x,y)=i∑∣xi−yi∣Input: x = [1,2,3], y = [2,4,6]
Output: 6.0
|1-2| + |2-4| + |3-6| = 1 + 2 + 3 = 6
Input: x = [-1,-2], y = [1,2]
Output: 6.0
|-1-1| + |-2-2| = 2 + 4 = 6
Input: x = [0,0,0], y = [0,0,0]
Output: 0.0
Convert inputs to NumPy arrays first, then use vectorized operations to compute absolute differences.
Sign in to take notes on this problem
Accepts: array
Accepts: array