Convert output of torch.nn.functional.pdist to a full matrix

I have a NM matrix of images where each row of M values represents a vector. I would like to compare these vectors with each other for which I am using pdist method as shown below. This method returns a 1-D tensor and I am not able find the index of any 2 vectors that matched completely (distance = 0). Is there a way I can get a NN matrix from this 1-D array?

a = torch.nn.functional.pdist(torch.rand(10, 10), p=2)
(a == 0).nonzero(as_tuple=True)[0]

As described in the docs, pdist is identical to the upper triangular portion, excluding the diagonal, of torch.norm(input[:, None] - input, dim=2, p=p)so you should be able to remap these values to these indices if needed.

I use scipy’s squareform function (scipy.spatial.distance.squareform — SciPy v1.11.1 Manual):

from scipy.spatial.distance import squareform
from torch import Tensor
import torch
tmp=torch.nn.functional.pdist(Tensor([[1,2],[3,4],[2,1]]))
print(Tensor(squareform(tmp)))
#stdout
tensor([[0.0000, 2.8284, 1.4142],
        [2.8284, 0.0000, 3.1623],
        [1.4142, 3.1623, 0.0000]])