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

PyTorch torch.typename function

PyTorch torch.typename function


PyTorch torch reference manual PyTorch torch reference manual

torch.typename is a function in PyTorch used to get the name of a data type. It takes a tensor or a data type as input and returns the string name of its type.

Function definition

torch.typename(input)


Usage examples

Example

import

torch

Get the type name of a tensor

x

=

torch.

tensor

(

[

1

,

2

,

3

]

,

dtype

=

torch.

float32

)

print

(

"float32 tensor type:"

,

torch.

typename

(

x

)

)

Get the type name of a data type

dtype

=

torch.

float64

print

(

"float64 type:"

,

torch.

typename

(

dtype

)

)

Complex type

y

=

torch.

tensor

(

[

1

+2j

]

,

dtype

=

torch.

complex64

)

print

(

"complex64 tensor type:"

,

torch.

typename

(

y

)

)

The output is:

float32 张量类型: torch.FloatTensor

float64 类型: torch.DoubleTensor

complex64 张量类型: torch.ComplexFloatTensor


PyTorch torch reference manual PyTorch torch reference manual