*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([torch.nan, -5, torch.inf, 8., -torch.inf, 3.+0.j, 3.+7.j, True]) torch.isreal(input=my_tensor) my_tensor.isreal() # tensor([True, True, True, True, True, True, False, True]) my_tensor = torch.tensor([[torch.nan, -5, torch.inf, 8.], [-torch.inf, 3.+0.j, 3.+7.j, True]]) torch.isreal(input=my_tensor) # tensor([[True, True, True, True], # [True, True, False, True]]) my_tensor = torch.tensor([[[torch.nan, -5], [torch.inf, 8.]], [[-torch.inf, 3.+0.j], [3.+7.j, True]]]) torch.isreal(input=my_tensor) # tensor([[[True, True], [True, True]], # [[True, True], [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([torch.nan, -5, torch.inf, 8., -torch.inf, 3.+0.j, 3.+7.j, True]) torch.isnan(input=my_tensor) my_tensor.isreal() # tensor([True, False, False, False, False, False, False, False]) my_tensor = torch.tensor([[torch.nan, -5, torch.inf, 8.], [-torch.inf, 3.+0.j, 3.+7.j, True]]) torch.isnan(input=my_tensor) # tensor([[True, False, False, False], # [False, False, False, False]]) my_tensor = torch.tensor([[[torch.nan, -5], [torch.inf, 8.]], [[-torch.inf, 3.+0.j], [3.+7.j, True]]]) torch.isnan(input=my_tensor) # tensor([[[True, False], [False, False]], # [[False, False], [False, 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([torch.nan, -5, torch.inf, 8., -torch.inf, 3.+0.j, 3.+7.j, True]) torch.isfinite(input=my_tensor) my_tensor.isfinite() # tensor([False, True, False, True, False, True, True, True]) my_tensor = torch.tensor([[torch.nan, -5, torch.inf, 8.], [-torch.inf, 3.+0.j, 3.+7.j, True]]) torch.isfinite(input=my_tensor) # tensor([[False, True, False, True], # [False, True, True, True]]) my_tensor = torch.tensor([[[torch.nan, -5], [torch.inf, 8.]], [[-torch.inf, 3.+0.j], [3.+7.j, True]]]) torch.isfinite(input=my_tensor) # tensor([[[False, True], [False, True]], # [[False, True], [True, True]]])
Top comments (0)