Is there any build in function for making 2D tensor from 1D tensor using specific calculation?
Hi I'm student who just started for deep learning.

For example, I have 1-D tensor x = [ 1 , 2]. From this one, I hope to make 2D tensor y whose (i,j)th element has value (x[i] - x[j]), i.e y[0,:] = [0  ,  1] , y[1,:]=[ -1 , 0].

Is there built-in function like this in pytorch library?

Thanks.

Here you need right dim of tensor to get expected result which you can get using torch.unsqueeze

x = torch.tensor([1 , 2])
y = x - x.unsqueeze(1)
y
tensor([[ 0,  1],
        [-1,  0]])

