快速鍵

torch.nn.functional.pdist

torch.nn.functional.pdist(input, p=2) Tensor

計算輸入中每對 row 向量之間的 p-norm 距離。這等同於 torch.norm(input[:, None] - input, dim=2, p=p) 的上三角部分,但不包括對角線。如果 rows 是連續的,此函數會更快。

如果 input 的形狀是 N×MN \times M,則輸出的形狀將會是 12N(N1)\frac{1}{2} N (N - 1)

如果 p(0,)p \in (0, \infty),則此函數等效於 scipy.spatial.distance.pdist(input, 'minkowski', p=p)。當 p=0p = 0 時,它等效於 scipy.spatial.distance.pdist(input, 'hamming') * M。當 p=p = \infty 時,最接近的 scipy 函數是 scipy.spatial.distance.pdist(xn, lambda x, y: np.abs(x - y).max())

參數
  • input – 形狀為 N×MN \times M 的輸入 tensor。

  • p – p 值,用於計算每個向量對之間的 p-norm 距離 [0,]\in [0, \infty]

文件

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