Buy Me a Coffee☕
*Memos:
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:
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]]])
The above is the detailed content of square in PyTorch. For more information, please follow other related articles on the PHP Chinese website!