当前位置:网站首页>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]])
边栏推荐
- DVWA installation tutorial (understand what you don't understand · in detail)
- Paginate the list collection and display the data on the page
- MySQL忘记密码怎么办
- [debug highlights] Expected input batch_size (1) to match target batch_size (0)
- 【MySQL8入门到精通】基础篇- Linux系统静默安装MySQL,跨版本升级
- CentOS7 - yum install mysql
- 快速掌握并发编程 --- 基础篇
- 12个MySQL慢查询的原因分析
- 1. 获取数据-requests.get()
- Temporal对比Cadence
猜你喜欢
Redis进阶 - 缓存问题:一致性、穿击、穿透、雪崩、污染等.
Redis Advanced - Cache Issues: Consistency, Penetration, Penetration, Avalanche, Pollution, etc.
Apache DButils使用注意事项--with modifiers “public“
Numpy中np.meshgrid的简单用法示例
ES 源码 API调用链路源码分析
Sun Wenlong, Secretary General of the Open Atom Open Source Foundation |
【JS面试题】面试官:“[1,2,3].map(parseInt)“ 输出结果是什么?答上来就算你通过面试
Tapdata 与 Apache Doris 完成兼容性互认证,共建新一代数据架构
关于小白安装nodejs遇到的问题(npm WARN config global `--global`, `--local` are deprecated. Use `--location=glob)
MySQL优化:从十几秒优化到三百毫秒
随机推荐
MySQL transaction isolation level, rounding
mysql存储过程
110 MySQL interview questions and answers (continuously updated)
Sun Wenlong, Secretary General of the Open Atom Open Source Foundation |
分布式事务处理方案大 PK!
再见了繁琐的Excel,掌握数据分析处理技术就靠它了
Unity手机游戏性能优化系列:针对CPU端的性能调优
Goodbye to the cumbersome Excel, mastering data analysis and processing technology depends on it
Apache DButils使用注意事项--with modifiers “public“
Refinement of the four major collection frameworks: Summary of List core knowledge
SQL row-column conversion
一文了解大厂的DDD领域驱动设计
PCL calculates the point cloud coordinate maximum and its index
110道 MySQL面试题及答案 (持续更新)
Mysql——字符串函数
Go中间件
限流的原理
MySQL事务(transaction) (有这篇就足够了..)
Pytorch教程Introduction中的神经网络实现示例
1. 获取数据-requests.get()