我们知道张量是一个数据的多维集合,那在进行常用算数运算时,张量是如何运算的呢?
pytorch在进行张量的算数运算时是将张量对应位置的元素进行算数运算,然后合并成一个相同大小的张量。
下面我们来看下在pytorch中如何进行张量的算数运算。
import torch
x = torch.tensor([1, 2, 3, 4])
y = torch.tensor([1, 2, 3, 4])
x + y
import torch
x = torch.tensor([1, 2, 3, 4])
y = torch.tensor([1, 2, 3, 4])
x - y
import torch
x = torch.tensor([1, 2, 3, 4])
y = torch.tensor([1, 2, 3, 4])
x * y
import torch
x = torch.tensor([1, 2, 3, 4])
y = torch.tensor([1, 2, 3, 4])
x / y
import torch
x = torch.tensor([1, 2, 3, 4])
y = torch.tensor([1, 2, 3, 4])
x ** y
通过运算结果看到,张量的算数运算都是对应位置元素的运算。
页面更新:2024-05-19
本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828
© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号