欢迎来到代码驿站!

Python代码

当前位置:首页 > 软件编程 > Python代码

Numpy与Pytorch 矩阵操作方式

时间:2021-07-20 08:55:30|栏目:Python代码|点击:

Numpy

随机矩阵: np.random.randn(d0, d1, d2, ...)

矩阵大小与形状: np.ndarray.size 与 np.dnarray.shape

Pytorch

随机矩阵: torch.randn(d0, d1, d2, ...)

添加维度: tensor.unsqueeze(0)

压缩维度: tensor.squeeze(0)

按维度拼接tensor: torch.cat(inputs, dim=0, ...)

维度堆叠: torch.stack(inputs, dim=0)

张量排序索引: tensor.sort(descending=True) 返回一个tensor为排序后的tensor, 一个为index_tensor

矩阵元素夹逼: tensor.clamp()

矩阵切割: torch.chunk(tensor, chunks, dim)

矩阵复制: torch.repeat(*size)

生成零矩阵: torch.torch.zeros(5, 3, dtype=torch.long)

生产同形状的随机矩阵:x = torch.randn_like(x, dtype=torch.float)

矩阵中函数名以'_'结尾的,如:y.add_(x),运算结束后会改变y本身

上一篇:python编程的核心知识点总结

栏    目:Python代码

下一篇:Python装饰器原理与简单用法实例分析

本文标题:Numpy与Pytorch 矩阵操作方式

本文地址:http://www.codeinn.net/misctech/159681.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有