mindspore.ops.pdist
- mindspore.ops.pdist(input, p=2.0)[source]
Calculates the distance between every pair of row vectors in the input using the p-norm. If the input input is a 2D Tensor with shape \((N, M)\), the output must be a 1D Tensor with shape \((N * (N - 1) / 2,)\). If input has batch dimension with shape \((*B, N, M)\), then the output must be a Tensor with shape \((*B, N * (N - 1) / 2)\).
\[y[n] = \sqrt[p]{{\mid x_{i} - x_{j} \mid}^p}\]where \(x_{i}, x_{j}\) are two different row vectors in the input.
- Parameters
- Returns
Tensor, has the same dtype as input.
- Raises
TypeError – If input is not a Tensor.
TypeError – If dtype of input is not float16, float32 or float64.
TypeError – If p is not a float.
ValueError – If p is a negative float.
ValueError – If dimension of input is less than 2.
- Supported Platforms:
GPU
CPU
Examples
>>> import numpy as np >>> from mindspore import Tensor, ops >>> x = Tensor(np.array([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0]]).astype(np.float32)) >>> y = ops.pdist(x, p=2.0) >>> print(y) [1.4142135 2.828427 1.4142135]