isnan¶
Documentation¶
-
treetensor.torch.
isnan
(input)[source]¶ In
treetensor
, you get a tree of new tensors with boolean elements representing if each element ofinput
is NaN or notExamples:
>>> import torch >>> import treetensor.torch as ttorch >>> ttorch.isnan(torch.tensor([1, float('inf'), 2, float('-inf'), float('nan')])) tensor([False, False, False, False, True]) >>> ttorch.isnan(ttorch.tensor({ ... 'a': [1, float('inf'), 2, float('-inf'), float('nan')], ... 'b': {'x': [[1, float('inf'), -2], [float('-inf'), 3, float('nan')]]} ... })) <Tensor 0x7fb782a2d0a0> ├── a --> tensor([False, False, False, False, True]) └── b --> <Tensor 0x7fb782a29d90> └── x --> tensor([[False, False, False], [False, False, True]])
Torch Version Related
This documentation is based on torch.isnan in torch v1.9.0+cu102. Its arguments’ arrangements depend on the version of pytorch you installed.
If some arguments listed here are not working properly, please check your pytorch’s version with the following command and find its documentation.
1 | python -c 'import torch;print(torch.__version__)' |
The arguments and keyword arguments supported in torch v1.9.0+cu102 is listed below.
Description From Torch v1.9.0+cu102¶
-
torch.
isnan
(input) → Tensor¶ Returns a new tensor with boolean elements representing if each element of
input
is NaN or not. Complex values are considered NaN when either their real and/or imaginary part is NaN.- Arguments:
input (Tensor): the input tensor.
- Returns:
A boolean tensor that is True where
input
is NaN and False elsewhere
Example:
>>> torch.isnan(torch.tensor([1, float('nan'), 2])) tensor([False, True, False])