mindspore.ops.Pdist

View Source On Gitee
class mindspore.ops.Pdist(p=2.0)[source]

Computes the p-norm distance between each pair of row vectors in the input.

Refer to mindspore.ops.pdist() for more details.

Note

The pdist operator involves exponentiation, the inf/nan calculation result may be generated when the float16 input is used. The float32 input is recommended.

Parameters

p (float, optional) – The order of norm distance, \(p∈[0, ∞)\). Default: 2.0 .

Inputs:
  • x (Tensor) - Input tensor. Supported dtypes: float16, float32 or float64.

Outputs:

Tensor, has the same dtype as x.

Supported Platforms:

GPU CPU

Examples

>>> from mindspore import Tensor, ops
>>> import numpy as np
>>> x = Tensor(np.array([[1.0, 1.0], [2.0, 2.0], [3.0, 3.0]]).astype(np.float32))
>>> op = ops.Pdist(p=2.0)
>>> y = op(x)
>>> print(y)
[1.4142135 2.828427  1.4142135]