PHP前端开发

PyTorch 中的子项目

百变鹏仔 5天前 #Python
文章标签 项目

请我喝杯咖啡☕

*备忘录:

sub() 可以与零个或多个元素或标量的 0d 或多个 d 张量中的两个或零个或多个元素的 0d 或多个 d 张量与一个标量进行减法,得到为零的 0d 或多个 d 张量或更多元素,如下所示:

*备忘录:

  • minus() 是 sub() 的别名。
  • import torchtensor1 = torch.tensor([9, 7, 6])tensor2 = torch.tensor([[4, -4, 3], [-2, 5, -5]])torch.sub(input=tensor1, other=tensor2)tensor1.sub(other=tensor2)torch.sub(input=tensor1, other=tensor2, alpha=1)torch.sub(input=tensor1, other=tensor2, alpha=torch.tensor(1))# tensor([[5, 11, 3], [11, 2, 11]])torch.sub(input=tensor1, other=tensor2, alpha=0)torch.sub(input=tensor1, other=tensor2, alpha=torch.tensor(0))# tensor([[9, 7, 6], [9, 7, 6]])torch.sub(input=tensor1, other=tensor2, alpha=2)torch.sub(input=tensor1, other=tensor2, alpha=torch.tensor(2))# tensor([[1, 15, 0], [13, -3, 16]])torch.sub(input=tensor1, other=tensor2, alpha=-1)torch.sub(input=tensor1, other=tensor2, alpha=torch.tensor(-1))# tensor([[13, 3, 9], [7, 12, 1]])torch.sub(input=tensor1, other=tensor2, alpha=-2)torch.sub(input=tensor1, other=tensor2, alpha=torch.tensor(-2))# tensor([[17, -1, 12], [5, 17, -4]])torch.sub(input=9, other=tensor2)torch.sub(input=9, other=tensor2, alpha=1)torch.sub(input=9, other=tensor2, alpha=torch.tensor(1))# tensor([[5, 13, 6], [11, 4, 14]])torch.sub(input=tensor1, other=4)torch.sub(input=tensor1, other=4, alpha=1)torch.sub(input=tensor1, other=4, alpha=torch.tensor(1))# tensor([5, 3, 2])torch.sub(input=9, other=4)torch.sub(input=9, other=4, alpha=1)torch.sub(input=9, other=4, alpha=torch.tensor(1))# tensor(5)tensor1 = torch.tensor([9., 7., 6.])tensor2 = torch.tensor([[4., -4., 3.], [-2., 5., -5.]])torch.sub(input=tensor1, other=tensor2)torch.sub(input=tensor1, other=tensor2, alpha=1.)torch.sub(input=tensor1, other=tensor2, alpha=torch.tensor(1.))# tensor([[5., 11., 3.], [11., 2., 11.]])torch.sub(input=9., other=tensor2)torch.sub(input=9., other=tensor2, alpha=1.)torch.sub(input=9., other=tensor2, alpha=torch.tensor(1.))# tensor([[5., 13., 6.], [11., 4., 14.]])torch.sub(input=tensor1, other=4)torch.sub(input=tensor1, other=4, alpha=1.)torch.sub(input=tensor1, other=4, alpha=torch.tensor(1.))# tensor([5., 3., 2.])torch.sub(input=9., other=4)torch.sub(input=9., other=4, alpha=1.)torch.sub(input=9., other=4, alpha=torch.tensor(1.))# tensor(5.)tensor1 = torch.tensor([9.+0.j, 7.+0.j, 6.+0.j])tensor2 = torch.tensor([[4.+0.j, -4.+0.j, 3.+0.j],                        [-2.+0.j, 5.+0.j, -5.+0.j]])torch.sub(input=tensor1, other=tensor2)torch.sub(input=tensor1, other=tensor2, alpha=1.+0.j)torch.sub(input=tensor1, other=tensor2, alpha=torch.tensor(1.+0.j))# tensor([[5.+0.j, 11.+0.j, 3.+0.j],#         [11.+0.j, 2.+0.j, 11.+0.j]])torch.sub(input=9.+0.j, other=tensor2)torch.sub(input=9.+0.j, other=tensor2, alpha=1.+0.j)torch.sub(input=9.+0.j, other=tensor2, alpha=torch.tensor(1.+0.j))# tensor([[5.+0.j, 13.+0.j, 6.+0.j],#         [11.+0.j, 4.+0.j, 14.+0.j]])torch.sub(input=tensor1, other=4.+0.j)torch.sub(input=tensor1, other=4.+0.j, alpha=1.+0.j)torch.sub(input=tensor1, other=4.+0.j, alpha=torch.tensor(1.+0.j))# tensor([5.+0.j, 3.+0.j, 2.+0.j])torch.sub(input=9.+0.j, other=4.+0.j)torch.sub(input=9.+0.j, other=4.+0.j, alpha=1.+0.j)torch.sub(input=9.+0.j, other=4.+0.j, alpha=torch.tensor(1.+0.j))# tensor(5.+0.j)