minkowski
Syntax
minkowski(X, Y, p, [weights])
Details
Compute the Minkowski distance between two numeric vectors (X and Y). The distance is defined as follows:
Parameters
X: A numeric vector.
Y: A numeric vector.
p: A numeric scalar with a value range of (0, +∞). NULL represents +∞.
Special values of p are defined as follows:
- p = 1: Manhattan distance
- p = 2: Euclidean distance
weights (optional): A non-negative numeric vector specifying the weights of each element in X and Y. The default value of each element is 1.
Note:
X, Y, and weights must have the same length.
Returns
A scalar of type DOUBLE.
Examples
Assume there are two vectors:
X = [1, 2]
Y = [4, 6]
- When p = 1, compute the Manhattan
distance:
minkowski(X,Y,p) // Output: 7
- When p = 2, compute the Euclidean
distance:
minkowski(X,Y,p) // Output:5
Related functions
