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

PyTorch torch.set_default_dtype function

PyTorch torch.set_default_dtype function


PyTorch torch reference manual PyTorch torch reference manual

torch.set_default_dtype is a function in PyTorch used to set the default floating-point data type.

Function definition

torch.set_default_dtype(d)


Usage examples

Example

import

torch

Set the default dtype to float64

torch.

set_default_dtype

(

torch.

float64

)

Create a tensor, using float64 by default

x

=

torch.

tensor

(

[

1.0

,

2.0

,

3.0

]

)

print

(

"Default dtype:"

,

x.

dtype

)

Restore the default

torch.

set_default_dtype

(

torch.

float32

)


PyTorch torch reference manual PyTorch torch reference manual