Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.dist function

PyTorch torch.dist function


PyTorch torch reference manual PyTorch torch reference manual

torch.dist is a PyTorch function for computing the distance between two tensors.

Function definition

torch.dist(input, other, p=2)


Parameter Description:


Usage examples

Example

import

torch

Create two tensors

x

=

torch.

tensor

(

[

1.0

,

2.0

,

3.0

]

)

y

=

torch.

tensor

(

[

4.0

,

5.0

,

6.0

]

)

Compute the Euclidean distance (p=2)

dist

=

torch.

dist

(

x

,

y

)

print

(

"Euclidean distance:"

,

dist

)

Compute the Manhattan distance (p=1)

dist_l1

=

torch.

dist

(

x

,

y

,

p

=

1

)

print

(

"Manhattan distance:"

,

dist_l1

)


PyTorch torch reference manual PyTorch torch reference manual