Shortcuts

torch.isfinite

torch.isfinite()

Returns a new tensor with boolean elements representing if each element is finite or not.

Real values are finite when they are not NaN, negative infinity, or infinity. Complex values are finite when both their real and imaginary parts are finite.

Arguments:

tensor (Tensor): A tensor to check

Returns:

Tensor: A torch.Tensor with dtype torch.bool containing a True at each location of finite elements and False otherwise

Example:

>>> torch.isfinite(torch.tensor([1, float('inf'), 2, float('-inf'), float('nan')]))
tensor([True,  False,  True,  False,  False])

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources