iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >pytorch常用函数之torch.randn()解读
  • 407
分享到

pytorch常用函数之torch.randn()解读

pytorch常用函数pytorchtorch.randn()pytorch函数 2023-02-02 12:02:12 407人浏览 八月长安

Python 官方文档:入门教程 => 点击学习

摘要

目录PyTorch常用函数torch.randn()pytorch torch.chunk(tensor, chunks, dim)总结pytorch常用函数torch.randn(

pytorch常用函数torch.randn()

torch.randn(*sizes, out=None) → Tensor

功能:从标准正态分布(均值为0,方差为1)中抽取的一组随机数。返回一个张量

  • sizes (int…) - 整数序列,定义输出张量的形状
  • out (Tensor, optinal) - 结果张量

eg:

random = torch.randn(2, 3)
out:  0.5419 0.1594 -0.0413
        -2.7937 0.9534 0.4561

pytorch torch.chunk(tensor, chunks, dim)

说明:在给定的维度上讲张量进行分块。

参数:

  • tensor(Tensor) -- 待分块的输入张量
  • chunks(int) -- 分块的个数
  • dim(int) -- 维度,沿着此维度进行分块
>>> x = torch.randn(3, 3)
>>> x
tensor([[ 1.0103,  2.3358, -1.9236],
        [-0.3890,  0.6594,  0.6664],
        [ 0.5240, -1.4193,  0.1681]])
>>> torch.chunk(x, 3, dim=0)
(tensor([[ 1.0103,  2.3358, -1.9236]]), tensor([[-0.3890,  0.6594,  0.6664]]), tensor([[ 0.5240, -1.4193,  0.1681]]))
>>> torch.chunk(x, 3, dim=1)
(tensor([[ 1.0103],
        [-0.3890],
        [ 0.5240]]), tensor([[ 2.3358],
        [ 0.6594],
        [-1.4193]]), tensor([[-1.9236],
        [ 0.6664],
        [ 0.1681]]))
>>> torch.chunk(x, 2, dim=1)
(tensor([[ 1.0103,  2.3358],
        [-0.3890,  0.6594],
        [ 0.5240, -1.4193]]), tensor([[-1.9236],
        [ 0.6664],
        [ 0.1681]]))

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。

--结束END--

本文标题: pytorch常用函数之torch.randn()解读

本文链接: https://www.lsjlt.com/news/193924.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作