How can I efficiently modify/make pairwise distance matrix?
    x_norm = (x**2).sum(1).view(-1, 1)
    if y is not None:
        y_norm = (y**2).sum(1).view(1, -1)
    else:
        y = x
        y_norm = x_norm.view(1, -1)
    dist = (x_norm + y_norm - 2.0 * torch.mm(x, torch.transpose(y, 0, 1)))
    return dist


Above is a code used to calculate pairwise distance matrix(M*N) between x (M points) and y (N points).

I hope to make pairwise distance matrix that has 0 element when distance between two points is larger than specific value 'T'.

In this case, what should I do?

Thanks

I think you are looking for torch.where:

new_dist = troch.where(dist &gt; T, dist, 0.)

