*Memos:
- My post explains isreal(), isnan() and isfinite().
- My post explains is_floating_point(), is_complex() and is_nonzero().
- My post explains isin().
- My post explains
torch.nan
andtorch.inf
.
isinf() can check if the zero or more elements of a 0D or more D tensor are infinity, getting the 0D or more D tensor of zero or more boolean values as shown below:
*Memos:
-
isinf()
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.isinf(input=my_tensor) my_tensor.isinf() # tensor([False, False, False, True, 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.isinf(input=my_tensor) # tensor([[False, False, False, True], # [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.isinf(input=my_tensor) # tensor([[[False, False], [False, True]], # [[False, False], [True, False]]])
isposinf() can if check the zero or more elements of a 0D or more D tensor are positive infinity, getting the 0D or more D tensor of zero or more boolean values as shown below:
*Memos:
-
isposinf()
can be used withtorch
or a tensor. - The 1st argument(
input
) withtorch
or using a tensor(Required-Type:tensor
ofint
,float
orbool
). - There is
out
argument withtorch
(Optional-Default:None
-Type:tensor
): *Memos:-
out=
must be used. - My post explains
out
argument.
-
import torch my_tensor = torch.tensor([8, 5., torch.nan, torch.inf, 3., 3.7, -torch.inf, True]) torch.isposinf(input=my_tensor) my_tensor.isposinf() # tensor([False, False, False, True, False, False, False, False]) my_tensor = torch.tensor([[8, 5., torch.nan, torch.inf], [3., 3.7, -torch.inf, True]]) torch.isposinf(input=my_tensor) # tensor([[False, False, False, True], # [False, False, False, False]]) my_tensor = torch.tensor([[[8, 5.], [torch.nan, torch.inf]], [[3., 3.7], [-torch.inf, True]]]) torch.isposinf(input=my_tensor) # tensor([[[False, False], [False, True]], # [[False, False], [False, False]]])
isneginf() can if check the zero or more elements of a 0D or more D tensor are negative infinity, getting the 0D or more D tensor of zero or more boolean values as shown below:
*Memos:
-
isneginf()
can be used withtorch
or a tensor. - The 1st argument(
input
) withtorch
or using a tensor(Required-Type:tensor
ofint
,float
orbool
). - There is
out
argument withtorch
(Optional-Default:None
-Type:tensor
): *Memos:-
out=
must be used. - My post explains
out
argument.
-
import torch my_tensor = torch.tensor([8, 5., torch.nan, torch.inf, 3., 3.7, -torch.inf, True]) torch.isneginf(input=my_tensor) my_tensor.isneginf() # tensor([False, False, False, False, False, False, True, False]) my_tensor = torch.tensor([[8, 5., torch.nan, torch.inf], [3., 3.7, -torch.inf, True]]) torch.isneginf(input=my_tensor) # tensor([[False, False, False, False], # [False, False, True, False]]) my_tensor = torch.tensor([[[8, 5.], [torch.nan, torch.inf]], [[3., 3.7], [-torch.inf, True]]]) torch.isneginf(input=my_tensor) # tensor([[[False, False], [False, False]], # [[False, False], [True, False]]])
Top comments (0)