1 """ 数学操作 """ 2 import torch 3 4 # torch.abs(input,out=None)计算输入张量每个元素的绝对值 5 a0 = torch.abs(torch.FloatTensor([-1, -2, 3])) 6 print(a0) 7 8 # torch.acos(input,out=None)计算输入张量每个元素的反余弦函数 9 a1 = torch.randn(4) 10 b1 = torch.acos(a1) 11 print(b1) 12 13 # torchasin(input,out=None)计算输入张量每个元素的反正弦函数 14 a2 = torch.randn(4) 15 b2 = torch.asin(a2) 16 print(b2) 17 18 # torch.add(input,value,out=None)对输入张量中的每个元素加上标量值value 19 a3 = torch.randn(4) 20 b3 = torch.add(a3, 20) 21 print(a3, "\n", b3) 22 23 # torch.add(input,value,other,out=None)将other张量中的每个元素乘标量值value,并加到输入张量input 24 other = torch.randn(4) 25 value = 20 26 a4 = torch.randn(4) 27 b4 = torch.add(a4, value, other) 28 print(b4) 29 30 # torch.addcdiv(tensor,value=1,tensor1,tensor2,out=None)用tensor2对tensor1逐元素相乘,然后乘以标量值value,并加到tensor 31 tensor = torch.randn(2, 3) 32 tensor1 = torch.randn(2, 3) 33 tensor2 = torch.randn(2, 3) 34 a5 = torch.addcdiv(tensor, 5, tensor2, tensor1) 35 print(a5) 36 37 #