Super Kai (Kazuya Ito)
Posted on May 17, 2024
*My post explains gcd() and lcm().
abs() can get the 0D or more D tensor of zero or more absolute values from the 0D or more D tensor of zero or more elements as shown below:
*Memos:
-
abs()
can be used with torch or a tensor. - The 1st argument(
input
) withtorch
or using a tensor(Required-Type:tensor
ofint
,float
orcomplex
). *If the type iscomplex
,float
is returned. - There is
out
argument withtorch
(Optional-Default:None
-Type:tensor
): *Memos:-
out=
must be used. -
My post explains
out
argument.
-
-
absolute() is the alias of
abs()
.
import torch
my_tensor = torch.tensor(7)
torch.abs(input=my_tensor)
my_tensor.abs()
# tensor(7)
my_tensor = torch.tensor([7, -1, 5, -7, -9, -3, 0, 6])
torch.abs(input=my_tensor)
# tensor([7, 1, 5, 7, 9, 3, 0, 6])
my_tensor = torch.tensor([[-7, 1, -5, 7],
[9, -3, 0, -6]])
torch.abs(input=my_tensor)
# tensor([[7, 1, 5, 7],
# [9, 3, 0, 6]])
my_tensor = torch.tensor([[7, -1, 5, -7],
[-9, -3, 0, 6]])
torch.abs(input=my_tensor)
# tensor([[[7, 1], [5, 7]],
# [[9, 3], [0, 6]]])
my_tensor = torch.tensor([[[7., -1.], [5., -7.]],
[[-9., -3.], [0., 6.]]])
torch.abs(input=my_tensor)
# tensor([[[7., 1.], [5., 7.]],
# [[9., 3.], [0., 6.]]])
my_tensor = torch.tensor([[[7.+0.j, -1.+0.j], [5.+0.j, -7.+0.j]],
[[-9.+0.j, -3.+0.j], [0.+0.j, 6.+0.j]]])
torch.abs(input=my_tensor)
# tensor([[[7., 1.], [5., 7.]],
# [[9., 3.], [0., 6.]]])
sqrt() can get the 0D or more D tensor of zero or more square roots from the 0D or more D tensor of zero or more elements as shown below:
*Memos:
-
sqrt()
can be used withtorch
or a tensor. - The 1st argument(
input
) withtorch
or using a tensor(Required-Type:tensor
ofint
,float
,complex
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(7)
torch.sqrt(input=my_tensor)
my_tensor.sqrt()
# tensor(2.6458)
my_tensor = torch.tensor([7, -1, 5, -7, -9, -3, 0, 6])
torch.sqrt(input=my_tensor)
# tensor([2.6458, nan, 2.2361, nan, nan, nan, 0.0000, 2.4495])
my_tensor = torch.tensor([[7, -1, 5, -7],
[-9, -3, 0, 6]])
torch.sqrt(input=my_tensor)
# tensor([[2.6458, nan, 2.2361, nan],
# [nan, nan, 0.0000, 2.4495]])
my_tensor = torch.tensor([[[7, -1],
[5, -7]],
[[-9, -3],
[0, 6]]])
torch.sqrt(input=my_tensor)
# tensor([[[2.6458, nan],
# [2.2361, nan]],
# [[nan, nan],
# [0.0000, 2.4495]]])
my_tensor = torch.tensor([[[7., -1.],
[5., -7.]],
[[-9., -3.],
[0., 6.]]])
torch.sqrt(input=my_tensor)
# tensor([[[2.6458, nan],
# [2.2361, nan]],
# [[nan, nan],
# [0.0000, 2.4495]]])
my_tensor = torch.tensor([[[7.+0.j, -1.+0.j],
[5.+0.j, -7.+0.j]],
[[-9.+0.j, -3.+0.j],
[0.+0.j, 6.+0.j]]])
torch.sqrt(input=my_tensor)
# tensor([[[2.6458+0.0000j, 0.0000+1.0000j],
# [2.2361+0.0000j, 0.0000+2.6458j]],
# [[0.0000+3.0000j, 0.0000+1.7321j],
# [0.0000+0.0000j, 2.4495+0.0000j]]])
my_tensor = torch.tensor([[[True, False],
[True, False]],
[[False, True],
[False, True]]])
torch.sqrt(input=my_tensor)
# tensor([[[1., 0.],
# [1., 0.]],
# [[0., 1.],
# [0., 1.]]])
💖 💪 🙅 🚩
Super Kai (Kazuya Ito)
Posted on May 17, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.