PyTorch torch.typename Function
PyTorch torch Reference Manual
torch.typenameIt is a function in PyTorch used to obtain the data type name. It accepts a tensor or a data type as input and returns the string name of its type.
Function Definition
torch.typename(input)
Usage Example
Example
import torch
# Get the type name of the tensor
x = torch.tensor([1, 2, 3], dtype=torch.float32)
print("float32 tensor type:", torch.typename(x))
# Get the type name of the 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))
# Get the type name of the tensor
x = torch.tensor([1, 2, 3], dtype=torch.float32)
print("float32 tensor type:", torch.typename(x))
# Get the type name of the 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 result is:
float32 张量类型: torch.FloatTensor float64 类型: torch.DoubleTensor complex64 张量类型: torch.ComplexFloatTensor
Other Extensions