*Memos:
- My post explains isreal(), isnan() and isfinite().
- My post explains isinf(), isposinf() and isneginf().
- My post explains isin().
-
My post explains
torch.nan
andtorch.inf
. - My post explains type promotion, result_type(), promote_types() and can_cast().
is_floating_point() can check if the 0D or more D tensor of zero or more elements is float
type, getting the scalar of a boolean value as shown below:
*Memos:
-
is_floating_point()
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([])
my_tensor = torch.tensor(5.)
my_tensor = torch.tensor(torch.nan)
my_tensor = torch.tensor(torch.inf)
torch.is_floating_point(input=my_tensor)
my_tensor.is_floating_point()
# True
my_tensor = torch.tensor(8)
my_tensor = torch.tensor(3.+0.j)
my_tensor = torch.tensor(3.+7.j)
my_tensor = torch.tensor(complex(torch.nan, torch.inf))
my_tensor = torch.tensor(True)
torch.is_floating_point(input=my_tensor)
# False
my_tensor = torch.tensor([5., torch.nan, torch.inf])
torch.is_floating_point(input=my_tensor)
# True
my_tensor = torch.tensor([8,
5.,
torch.nan,
torch.inf,
3.+0.j,
3.+7.j,
complex(torch.nan, torch.inf),
True])
my_tensor = torch.tensor([[8,
5.,
torch.nan,
torch.inf],
[3.+0.j,
3.+7.j,
complex(torch.nan, torch.inf),
True]])
my_tensor = torch.tensor([[[8,
5.],
[torch.nan,
torch.inf]],
[[3.+0.j,
3.+7.j],
[complex(torch.nan, torch.inf),
True]]])
torch.is_floating_point(input=my_tensor)
# False
is_complex() can check if the 0D or more D tensor of zero or more elements is complex
type, getting the scalar of a boolean value as shown below:
*Memos:
-
is_complex()
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(3.+0.j)
my_tensor = torch.tensor(3.+7.j)
my_tensor = torch.tensor(complex(torch.nan, torch.inf))
torch.is_complex(input=my_tensor)
my_tensor.is_complex()
# True
my_tensor = torch.tensor([])
my_tensor = torch.tensor(8)
my_tensor = torch.tensor(5.)
my_tensor = torch.tensor(torch.nan)
my_tensor = torch.tensor(torch.inf)
my_tensor = torch.tensor(True)
torch.is_complex(input=my_tensor)
# False
my_tensor = torch.tensor([3.+0.j, 3.+7.j, complex(torch.nan, torch.inf)])
torch.is_complex(input=my_tensor)
# True
my_tensor = torch.tensor([8,
5.,
torch.nan,
torch.inf,
3.+0.j,
3.+7.j,
complex(torch.nan, torch.inf),
True])
my_tensor = torch.tensor([[8,
5.,
torch.nan,
torch.inf],
[3.+0.j,
3.+7.j,
complex(torch.nan, torch.inf),
True]])
my_tensor = torch.tensor([[[8,
5.],
[torch.nan,
torch.inf]],
[[3.+0.j,
3.+7.j],
[complex(torch.nan, torch.inf),
True]]])
torch.is_complex(input=my_tensor)
# True
is_nonzero() can check if the 0D or more D tensor of only one element is a nonzero, getting the scalar of a boolean value as shown below:
*Memos:
-
is_nonzero()
can be used withtorch
or a tensor. - The 1st argument(
input
) withtorch
or using a tensor(Required-Type:tensor
ofint
,float
,complex
orbool
). - There must be only one element in a tensor.
import torch
my_tensor = torch.tensor(8)
my_tensor = torch.tensor(5.)
my_tensor = torch.tensor([torch.nan])
my_tensor = torch.tensor([torch.inf])
my_tensor = torch.tensor([[3.+0.j]])
my_tensor = torch.tensor([[3.+7.j]])
my_tensor = torch.tensor([[[complex(torch.nan, torch.inf)]]])
my_tensor = torch.tensor([[[True]]])
torch.is_nonzero(input=my_tensor)
my_tensor.is_nonzero()
# True
my_tensor = torch.tensor(0)
my_tensor = torch.tensor([0.])
my_tensor = torch.tensor([[0.+0.j]])
my_tensor = torch.tensor([[[False]]])
torch.is_nonzero(input=my_tensor)
# False
Top comments (0)