mindspore.ops.pdist
- mindspore.ops.pdist(x, p=2.0)[source]
Computes the p-norm distance between each pair of row vectors in the input. If x is a 2D Tensor of shape \((N, M)\), then output must be a 1D Tensor of shape \((N * (N - 1) / 2,)\). If x is a Tensor of shape \((*B, N, M)\), then output must be a Tensor of 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 x.
- Raises
TypeError – If x is not a Tensor.
TypeError – If dtype of x is not float16, float32 or float64.
TypeError – If p is not a float.
ValueError – If p is a negative float.
ValueError – If dimension of x is less than 2.
- Supported Platforms:
CPU
Examples
>>> 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]