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(N1)/2,). If x is a Tensor of shape (B,N,M), then output must be a Tensor of shape (B,N(N1)/2).

y[n]=xixjpp

where xi,xj are two different row vectors in the input.

Parameters
  • x (Tensor) – Input tensor of shape (B,N,M). B is batch size, one-dim or multi-dim. dtype: float16, float32 or float64.

  • p (float) – p value for the p-norm distance to calculate between each vector pair. p[0,]. Default: 2.0.

Returns

Tensor, has the same dtype as x.

Raises
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]