PyTorch torch.is_floating_point Function
PyTorch torch Reference Manual
torch.is_floating_pointIt is a function in PyTorch used to check whether the data type of a tensor is a floating-point type.
Function Definition
torch.is_floating_point(input)
Usage Example
Example
import torch
# Floating-point tensor
x = torch.tensor([1.0, 2.0, 3.0])
print("Floating point:", torch.is_floating_point(x))
# Integer tensor
y = torch.tensor([1, 2, 3])
print("Integer:", torch.is_floating_point(y))
# Floating-point tensor
x = torch.tensor([1.0, 2.0, 3.0])
print("Floating point:", torch.is_floating_point(x))
# Integer tensor
y = torch.tensor([1, 2, 3])
print("Integer:", torch.is_floating_point(y))
The output result is:
浮点数: True 整数: False
Other Extensions