*Memos:
- My post explains pow().
- My post explains float_power().
- My post explains abs() and sqrt().
- My post explains gcd() and lcm().
- My post explains trace(), reciprocal() and rsqrt().
square() can get the 0D or more D tensor of squared zero or more elements, getting the 0D or more D tensor of zero or more elements as shown below:
*Memos:
-
square()can be used with torch or a tensor. - The 1st argument(
input) withtorchor using a tensor(Required-Type:tensorofint,float,complexorbool). - There is
outargument withtorch(Optional-Default:None-Type:tensor): *Memos:-
out=must be used. -
My post explains
outargument.
-
import torch
my_tensor = torch.tensor(-3)
torch.square(input=my_tensor)
my_tensor.square()
# tensor(9)
my_tensor = torch.tensor([-3, 1, -2, 3, 5, -5, 0, -4])
torch.square(input=my_tensor)
# tensor([9, 1, 4, 9, 25, 25, 0, 16])
my_tensor = torch.tensor([[-3, 1, -2, 3],
[5, -5, 0, -4]])
torch.square(input=my_tensor)
# tensor([[9, 1, 4, 9],
# [25, 25, 0, 16]])
my_tensor = torch.tensor([[[-3, 1], [-2, 3]],
[[5, -5], [0, -4]]])
torch.square(input=my_tensor)
# tensor([[[9, 1], [4, 9]],
# [[25, 25], [0, 16]]])
my_tensor = torch.tensor([[[-3., 1.], [-2., 3.]],
[[5., -5.], [0., -4.]]])
torch.square(input=my_tensor)
# tensor([[[9., 1.], [4., 9.]],
# [[25., 25.], [0., 16.]]])
my_tensor = torch.tensor([[[-3.+0.j, 1.+0.j], [-2.+0.j, 3.+0.j]],
[[5.+0.j, -5.+0.j], [0.+0.j, -4.+0.j]]])
torch.square(input=my_tensor)
# tensor([[[9.-0.j, 1.+0.j], [4.-0.j, 9.+0.j]],
# [[25.+0.j, 25.-0.j], [0.+0.j, 16.-0.j]]])
my_tensor = torch.tensor([[[True, False], [True, False]],
[[False, True], [False, True]]])
torch.square(input=my_tensor)
# tensor([[[1, 0], [1, 0]],
# [[0, 1], [0, 1]]])
Top comments (0)