Table of Contents
Shortcuts

# 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×M N \times M N×M then the output will have shape 1 2 N(N−1)\frac{1}{2} N (N - 1)2 1​N(N−1).

  This function is equivalent to `scipy.spatial.distance.pdist(input, 'minkowski', p=p)` if p∈(0,∞)p \in (0, \infty)p∈(0,∞). When p=0 p = 0 p=0 it is equivalent to `scipy.spatial.distance.pdist(input, 'hamming') * M`. When p=∞p = \infty p=∞, 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×M N \times M N×M.

    - p – p value for the p-norm distance to calculate between each vector pair ∈[0,∞]\in [0, \infty]∈[0,∞].

## Docs

Access comprehensive developer documentation for PyTorch

View Docs

## Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

## Resources

Find development resources and get your questions answered

View Resources

To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.