pytorch 基础数学运算
代码语言:javascript
复制# -*- coding:utf-8 -*-
# /usr/bin/python
'''
-------------------------------------------------
File Name : base_math
Description :
Envs :
Author : yanerrol
Date : 2019/12/23 22:50
-------------------------------------------------
Change Activity:
2019/12/23 22:50:
-------------------------------------------------
'''
__author__ = 'yanerrol'
import torch
a = torch.rand(3,4)
b = torch.rand(4)
# 每行对应的元素都增加
c = a b
print('na',a,'nb',b,'nc',c)
# 每行对应的元素相加
c = torch.add(a,b)
print(c)
c = a-b-(torch.sub(a,b))
print(c)
# 除
c = a/b-torch.div(a,b)
print(c)
# #
# # # a = torch.tensor([[3,3],[3,3]])
# # # b = torch.ones(2,2)
# # # b = torch.ones([2,2])
# # # print(b,b)
# # # c = a@b
# # # print(c)
# 指数
a = torch.full([2,2],3)
b = a.pow(2)
pr