0. 往期内容
[二]深度学习Pytorch-张量的操作:拼接、切分、索引和变换
[七]深度学习Pytorch-DataLoader与Dataset(含人民币二分类实战)
[八]深度学习Pytorch-图像预处理transforms
[九]深度学习Pytorch-transforms图像增强(剪裁、翻转、旋转)
[十]深度学习Pytorch-transforms图像操作及自定义方法
深度学习Pytorch-张量数学运算
1.概览

2. 常用函数
2.1 torch.add(input, other, alpha=1)
torch.add(input, other, alpha=1, out=None)
(1)功能:逐元素计算input+alpha*other;
(2)参数:
input: 第一个张量;
alpha: 乘项因子;
other: 第二个张量;
(3)代码示例:
# ======================================= example 8 =======================================
# torch.add
# flag = True
flag = False
if flag:
#创建数值为标准正态分布,大小为3*3的张量
t_0 = torch.randn((3, 3))
#创建与t_0相同大小的全1张量
t_1 = torch.ones_like(t_0)
#t_add的每个元素都等于t_0对应元素+10*t_1对应元素
t_add = torch.add(t_0, 10, t_1)
print("t_0:\n{}\nt_1:\n{}\nt_add_10:\n{}".format(t_0, t_1, t_add))

>>> a = torch.randn(4)
>>> a
tensor([ 0.0202, 1.0985, 1.3506

最低0.47元/天 解锁文章
4209

被折叠的 条评论
为什么被折叠?



