euclidean#
- mvpy.math.euclidean(x: ndarray | Tensor, y: ndarray | Tensor, *args: Any) ndarray | Tensor[source]#
Computes euclidean distances between x and y.
- Parameters:
- xUnion[np.ndarray, torch.Tensor]
Matrix ([samples …] x features)
- yUnion[np.ndarray, torch.Tensor]
Matrix ([samples …] x features)
- Returns:
- Union[np.ndarray, torch.Tensor]
Vector or matrix of euclidean distances
Notes
Euclidean distances are defined as:
\[d(x, y) = \sqrt{\sum_{i=1}^n (x_i - y_i)^2}\]where \(x_i\) and \(y_i\) are the \(i\)-th elements of \(x\) and \(y\), respectively.
Examples
>>> import torch >>> import mvpy as mv >>> x, y = torch.normal(0, 1, (10, 50)), torch.normal(0, 1, (10, 50)) >>> d = mv.math.euclidean(x, y) >>> d.shape torch.Size([10])