当前位置: 首页 > news >正文

企业网站维护赣州seo唐三

企业网站维护,赣州seo唐三,wordpress 评论ajax分页,合川网站建设公司文章目录 1. 张量数值计算1. 1 张量基本运算1.2 点乘运算1.3 矩阵运算 2. 张量运算函数 1. 张量数值计算 1. 1 张量基本运算 加减乘除取负号: add、sub、mul、div、neg add_ 、sub_、 mul_ 、div_、 neg_ (其中带下划线的版本会修改原数据) data torch.randin…

文章目录

    • 1. 张量数值计算
      • 1. 1 张量基本运算
      • 1.2 点乘运算
      • 1.3 矩阵运算
    • 2. 张量运算函数

1. 张量数值计算

1. 1 张量基本运算

加减乘除取负号:

addsubmuldivneg

add_ sub_、 mul_ div_neg_ (其中带下划线的版本会修改原数据)

data = torch.randint(0,10,[2,3])
print(data)
# 不修改原数据 相当于 data = data + 5
new_data=data.add(5)
print(new_data)
# 修改原数据 相当于 data += 3
data.add_(3)
print(data)

输出结果:

tensor([[8, 8, 4],[4, 1, 0]])
tensor([[13, 13,  9],[ 9,  6,  5]])
tensor([[11, 11,  7],[ 7,  4,  3]])

1.2 点乘运算

点乘运算是指两个同维矩阵相同位置的元素相乘,使用 mul或 运算发 *实现。

data1 = torch.randint(0,10,[2,3])
data2 = torch.randint(0,10,[2,3])
data3 = data1.mul(data2)
data4 = data1*data2
print(data1)
print(data2)
print(data3)
print(data4)

输出结果:

tensor([[4, 3, 8],[7, 4, 6]])
tensor([[0, 1, 9],[9, 8, 0]])
tensor([[ 0,  3, 72],[63, 32,  0]])
tensor([[ 0,  3, 72],[63, 32,  0]])

1.3 矩阵运算

矩阵乘法运算要求第一个矩阵 shape: (n, m),第二个矩阵 shape: (m, p), 两个矩阵点积运算 shape 为: (n, p)。

  1. 运算符 @ 用于进行两个矩阵的乘积运算
  2. torch.matmul对进行乘积运算的两矩阵形状没有限定.对数输入的 shape 不同的张量, 对应的最后几个维度必须符合
    矩阵运算规则
data1 = torch.tensor([[1, 2], [3, 4], [5, 6]])
data2 = torch.tensor([[5, 6], [7, 8]])
print('data1--->',data1)
print('data2--->',data2)
data3 = data1 @ data2
print('data3--->',data3)
data4 = torch.matmul(data1, data2)
print('data4--->',data4)

输出结果:

data1---> tensor([[1, 2],[3, 4],[5, 6]])
data2---> tensor([[5, 6],[7, 8]])
data3---> tensor([[19, 22],[43, 50],[67, 78]])
data4---> tensor([[19, 22],[43, 50],[67, 78]])

2. 张量运算函数

PyTorch 为每个张量封装了很多实用的计算函数:

  • 均值
  • 平方根
  • 求和
  • 指数计算
  • 对数计算等等
data = torch.randint(1,10,[2,3],dtype=torch.float64)
print('data--->',data)
# 1. 计算均值
# 注意:tensor 必须为 Float 或者 Double 类型
print('均值:',data.mean())
print('列计算均值:',data.mean(dim=0))
print('行计算均值:',data.mean(dim=0))
# 2. 计算总和
print('求和:',data.sum())
print('列求和:',data.sum(dim=0))
print("行求和:",data.sum(dim=1))
# 3. 计算平方
print('平方:',torch.pow(data,2))
# 4. 计算平方根
print('平方根:',data.sqrt())
# 5. 指数计算,e ^ n 次方
print('e ^ n 次方:',data.exp())
# 6. 对数计算
print('e为底:',data.log())
print('2为底:',data.log2())
print('10为底:',data.log10())

输出结果:

data---> tensor([[8., 6., 7.],[9., 3., 7.]], dtype=torch.float64)
均值: tensor(6.6667, dtype=torch.float64)
列计算均值: tensor([8.5000, 4.5000, 7.0000], dtype=torch.float64)
行计算均值: tensor([8.5000, 4.5000, 7.0000], dtype=torch.float64)
求和: tensor(40., dtype=torch.float64)
列求和: tensor([17.,  9., 14.], dtype=torch.float64)
行求和: tensor([21., 19.], dtype=torch.float64)
平方: tensor([[64., 36., 49.],[81.,  9., 49.]], dtype=torch.float64)
平方根: tensor([[2.8284, 2.4495, 2.6458],[3.0000, 1.7321, 2.6458]], dtype=torch.float64)
e ^ n 次方: tensor([[2980.9580,  403.4288, 1096.6332],[8103.0839,   20.0855, 1096.6332]], dtype=torch.float64)
e为底: tensor([[2.0794, 1.7918, 1.9459],[2.1972, 1.0986, 1.9459]], dtype=torch.float64)
2为底: tensor([[3.0000, 2.5850, 2.8074],[3.1699, 1.5850, 2.8074]], dtype=torch.float64)
10为底: tensor([[0.9031, 0.7782, 0.8451],[0.9542, 0.4771, 0.8451]], dtype=torch.float64)
http://www.hkea.cn/news/605211/

相关文章:

  • 网站开发有前途吗我也要投放广告
  • 备案 网站名称怎么写crm软件
  • 扁平式网站模板b2b网站推广优化
  • 做外贸网站网络营销咨询服务
  • 江门网站建设方案报价淘宝seo优化怎么做
  • 盘龙城做网站推广网站推广
  • 如何做电子书网站域名站长工具
  • 物联网平台有哪些排名优化外包公司
  • 秦皇岛汽车网站制作数字营销工具
  • 培训教育的网站怎么做东莞做网站的联系电话
  • 云南做网站的公司外贸谷歌优化
  • 网页设计学徒培训可试学巢湖seo推广
  • 让顾客心动的句子seo模拟点击软件源码
  • 设计类专业包括哪些kj6699的seo综合查询
  • 手机网站制作哪家好查关键词
  • 米拓企业网站管理系统电商培训机构排名前十
  • 做效果图有哪些网站seo点击排名
  • 网络营销推广网站收录seo推广排名平台有哪些
  • 产品经理如何看待网站开发广州软件系统开发seo推广
  • wordpress 忘记管理员如何做网站seo
  • app和网站哪个有优势淘宝关键词排名
  • wordpress该域名宁波网站seo公司
  • 建购物网站怎么建呀简单的网站建设
  • 江苏省建设教育协会网站首页百度知道合伙人答题兼职入口
  • 做优化的网站平台搭建
  • 做网站需要多久网络推广是什么专业
  • 厦门加盟网站建设线上推广营销
  • 定制网站案例seo搜索引擎优化薪酬
  • 网站制作成功后怎么使用浏览器观看b站视频的最佳设置
  • 一家专门做开网店的网站北京seo专员