Rate this Page

torch.isfinite#

torch.isfinite(input)Tensor#

Returns a new tensor with boolean elements representing if each element isfinite 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.

Parameters

input (Tensor) – the input tensor.

Returns

A boolean tensor that is True whereinput is finite and False elsewhere

Example:

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