## Example Usage ## Example import torch # Create a tensor with various values x = torch.tensor([1.0,float('inf'),float('nan'),2.0]) # Check for finite values result = torch.isfinite(x) print(result) Output: tensor([True, False, False, True])
Pytorch Torch Isfinite
# PyTorch torch.isfinite Function
PyTorch torch Reference
`torch.isfinite` is a PyTorch function used to check if tensor elements have finite values. Returns a boolean tensor where each element is True if it is a finite value (not infinity or NaN).
### Function Definition
torch.isfinite(input)
## Example Usage ## Example import torch # Create a tensor with various values x = torch.tensor([1.0,float('inf'),float('nan'),2.0]) # Check for finite values result = torch.isfinite(x) print(result) Output: tensor([True, False, False, True])
PyTorch torch Reference
PyTorch Data Transforms
PyTorch torch.nn Reference
Xunfei Starry Coding Plan includes free model call quotas for DeepSeek, GLM, Kimi, MiniMax, one-stop experience and deployment platform. Configuration Guide Β₯3.9/month Immediate Activation
## Example Usage ## Example import torch # Create a tensor with various values x = torch.tensor([1.0,float('inf'),float('nan'),2.0]) # Check for finite values result = torch.isfinite(x) print(result) Output: tensor([True, False, False, True])
YouTip