*Memos:
- My post explains isinf(), isposinf() and isneginf().
- My post explains is_floating_point(), is_complex() and is_nonzero().
- My post explains isin().
-
My post explains
torch.nan
andtorch.inf
.
isreal() can check if the zero or more elements of a 0D or more D tensor are real-valued, getting the 0D or more D tensor of zero or more boolean values as shown below:
*Memos:
-
isreal()
can be used with torch or a tensor. - The 1st argument(
input
) withtorch
or using a tensor(Required-Type:tensor
ofint
,float
,complex
orbool
).
import torch
my_tensor = torch.tensor([8,
5.,
torch.nan,
torch.inf,
3.+0.j,
3.+7.j,
complex(torch.nan, torch.inf),
True])
torch.isreal(input=my_tensor)
my_tensor.isreal()
# tensor([True, True, True, True, True, False, False, True])
my_tensor = torch.tensor([[8,
5.,
torch.nan,
torch.inf],
[3.+0.j,
3.+7.j,
complex(torch.nan, torch.inf),
True]])
torch.isreal(input=my_tensor)
# tensor([[True, True, True, True],
# [True, False, False, True]])
my_tensor = torch.tensor([[[8,
5.],
[torch.nan,
torch.inf]],
[[3.+0.j,
3.+7.j],
[complex(torch.nan, torch.inf),
True]]])
torch.isreal(input=my_tensor)
# tensor([[[True, True], [True, True]],
# [[True, False], [False, True]]])
isnan() can check if the zero or more elements of a 0D or more D tensor are NaN(Not a Number), getting the 0D or more D tensor of zero or more boolean values shown below:
*Memos:
-
isnan()
can be used withtorch
or a tensor. - The 1st argument(
input
) withtorch
or using a tensor(Required-Type:tensor
ofint
,float
,complex
orbool
).
import torch
my_tensor = torch.tensor([8,
5.,
torch.nan,
torch.inf,
3.+0.j,
3.+7.j,
complex(torch.nan, torch.inf),
True])
torch.isnan(input=my_tensor)
my_tensor.isreal()
# tensor([False, False, True, False, False, False, True, False])
my_tensor = torch.tensor([[8,
5.,
torch.nan,
torch.inf],
[3.+0.j,
3.+7.j,
complex(torch.nan, torch.inf),
True]])
torch.isnan(input=my_tensor)
# tensor([[False, False, True, False],
# [False, False, True, False]])
my_tensor = torch.tensor([[[8,
5.],
[torch.nan,
torch.inf]],
[[3.+0.j,
3.+7.j],
[complex(torch.nan, torch.inf),
True]]])
torch.isnan(input=my_tensor)
# tensor([[[False, False], [True, False]],
# [[False, False], [True, False]]])
isfinite() can check if the zero or more elements of a 0D or more D tensor are finity, getting the 0D or more D tensor of zero or more boolean values as shown below:
*Memos:
-
isfinite()
can be used withtorch
or a tensor. - The 1st argument(
input
) withtorch
or using a tensor(Required-Type:tensor
ofint
,float
,complex
orbool
).
import torch
my_tensor = torch.tensor([8,
5.,
torch.nan,
torch.inf,
3.+0.j,
3.+7.j,
complex(torch.nan, torch.inf),
True])
torch.isfinite(input=my_tensor)
my_tensor.isfinite()
# tensor([True, True, False, False, True, True, False, True])
my_tensor = torch.tensor([[8,
5.,
torch.nan,
torch.inf],
[3.+0.j,
3.+7.j,
complex(torch.nan, torch.inf),
True]])
torch.isfinite(input=my_tensor)
# tensor([[True, True, False, False],
# [True, True, False, True]])
my_tensor = torch.tensor([[[8,
5.],
[torch.nan,
torch.inf]],
[[3.+0.j,
3.+7.j],
[complex(torch.nan, torch.inf),
True]]])
torch.isfinite(input=my_tensor)
# tensor([[[True, True], [False, False]],
# [[True, True], [False, True]]])