当前位置:网站首页>torch.normal函数用法
torch.normal函数用法
2022-07-31 05:09:00 【Cheng-O】
官方文档给的用法:
torch.normal(means, std, out=None)
意思为means给定tensor的均值范围和形状,std给出每个均值服从的标准差
官方示例:
torch.normal(means=torch.arange(1, 11), std=torch.arange(1, 0, -0.1))
1.5104
1.6955
2.4895
4.9185
4.9895
6.9155
7.3683
8.1836
8.7164
9.8916
[torch.FloatTensor of size 10]
实际情况:
>>> torch.normal(means=torch.arange(1, 11), std=torch.arange(1, 0, -0.1))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: normal() received an invalid combination of arguments - got (means=Tensor, std=Tensor, ), but expected one of:
* (Tensor mean, Tensor std, *, torch.Generator generator, Tensor out)
* (Tensor mean, float std, *, torch.Generator generator, Tensor out)
* (float mean, Tensor std, *, torch.Generator generator, Tensor out)
* (float mean, float std, tuple of ints size, *, torch.Generator generator, Tensor out, torch.dtype dtype, torch.layout layout, torch.device device, bool pin_memory, bool requires_grad)
从错误类型中看出现在torch中已经不再使用means而是使用mean,即只能生成固定均值的正态分布。
正确的打开方式:
采用第四种:
torch.normal(mean, std, size)
三个参数分别为均值,标准差和size
>>> torch.normal(3, 0.1, (3, 4))
tensor([[2.9425, 3.1877, 2.9735, 3.0982],
[3.0061, 2.9918, 2.7953, 3.0066],
[2.8219, 2.9578, 2.8813, 2.9014]])
采用第三种:
torch.normal(mean, stds)
两个参数分别为:均值和标准差,使用标准差来确定范围size
>>> torch.normal(3, torch.ones(3, 4)/10)
tensor([[2.8491, 3.0263, 3.0888, 3.0818],
[3.1101, 2.7490, 3.1847, 3.0861],
[2.8530, 2.8666, 2.9634, 3.1875]])
边栏推荐
- MySQL database addition, deletion, modification and query (detailed explanation of basic operation commands)
- 再见了繁琐的Excel,掌握数据分析处理技术就靠它了
- 快速掌握并发编程 --- 基础篇
- ES source code API call link source code analysis
- mysql使用on duplicate key update批量更新数据
- 1. 获取数据-requests.get()
- DVWA靶场环境搭建
- ERROR 2003 (HY000) Can't connect to MySQL server on 'localhost3306' (10061)
- With MVC, why DDD?
- Numpy中np.meshgrid的简单用法示例
猜你喜欢
Unity Framework Design Series: How Unity Designs Network Frameworks
Error EPERM operation not permitted, mkdir 'Dsoftwarenodejsnode_cache_cacach Two solutions
12个MySQL慢查询的原因分析
面试官:生成订单30分钟未支付,则自动取消,该怎么实现?
【LeetCode-SQL每日一练】——2. 第二高的薪水
【一起学Rust】Rust学习前准备——注释和格式化输出
MySQL (updating)
Centos7 install mysql5.7 steps (graphical version)
Go language study notes - dealing with timeout problems - Context usage | Go language from scratch
矩池云快速安装torch-sparse、torch-geometric等包
随机推荐
Unity Tutorial: URP Rendering Pipeline Practical Tutorial Series [1]
datagrip带参sql查询
太厉害了,终于有人能把文件上传漏洞讲的明明白白了
Mysql application cannot find my.ini file after installation
SQL row-column conversion
MySQL database installation (detailed)
Interview Redis High Reliability | Master-Slave Mode, Sentinel Mode, Cluster Cluster Mode
再见了繁琐的Excel,掌握数据分析处理技术就靠它了
[R language] [3] apply, tapply, lapply, sapply, mapply and par function related parameters
.NET-9. A mess of theoretical notes (concepts, ideas)
Pytorch教程Introduction中的神经网络实现示例
sql语句-如何以一个表中的数据为条件据查询另一个表中的数据
Minio上传文件ssl证书不受信任
The Vue project connects to the MySQL database through node and implements addition, deletion, modification and query operations
MYSQL一站式学习,看完即学完
ERROR 2003 (HY000) Can't connect to MySQL server on 'localhost3306' (10061)Solution
Information System Project Manager Core Test Site (55) Configuration Manager (CMO) Work
如何将项目部署到服务器上(全套教程)
为什么要用Flink,怎么入门使用Flink?
110道 MySQL面试题及答案 (持续更新)