Rate this Page
โ˜… โ˜… โ˜… โ˜… โ˜…

torch.nn.functional.pdist#

torch.nn.functional.pdist(input, p=2) โ†’ Tensor#

Computes the p-norm distance between every pair of row vectors in the input. This is identical to the upper triangular portion, excluding the diagonal, of torch.norm(input[:, None] - input, dim=2, p=p). This function will be faster if the rows are contiguous.

If input has shape Nร—MN \times M then the output will have shape 12N(Nโˆ’1)\frac{1}{2} N (N - 1).

This function is equivalent to scipy.spatial.distance.pdist(input, 'minkowski', p=p) if pโˆˆ(0,โˆž)p \in (0, \infty). When p=0p = 0 it is equivalent to scipy.spatial.distance.pdist(input, 'hamming') * M. When p=โˆžp = \infty, the closest scipy function is scipy.spatial.distance.pdist(xn, lambda x, y: np.abs(x - y).max()).

Parameters
  • input โ€“ input tensor of shape Nร—MN \times M.

  • p โ€“ p value for the p-norm distance to calculate between each vector pair โˆˆ[0,โˆž]\in [0, \infty].