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

作者:土豆豆豆豆豆 时间:2023-03-24 09:08:29 

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]]))

来源:https://blog.csdn.net/JannyYang/article/details/100514037

标签:pytorch,函数,torch.randn()
0
投稿

猜你喜欢

  • Python任务调度模块APScheduler使用

    2021-08-23 05:45:44
  • python机器学习朴素贝叶斯算法及模型的选择和调优详解

    2022-05-16 00:38:26
  • MySql中的常用参数查询

    2024-01-18 06:00:30
  • 利用nodejs读取图片并将二进制数据转换成base64格式

    2024-05-08 09:37:21
  • Mysql5.7.11在windows10上的安装与配置(解压版)

    2024-01-13 18:07:49
  • Python中的流程控制详解

    2023-07-22 20:31:54
  • Python如何优雅获取本机IP方法

    2021-03-07 15:46:16
  • 详解python环境安装selenium和手动下载安装selenium的方法

    2023-10-05 18:07:07
  • JavaScript 中级笔记 第四章 闭包

    2024-04-18 10:53:09
  • .NET Core2.1如何获取自定义配置文件信息详解

    2023-07-17 16:26:34
  • MySQL优化配置文件my.ini(discuz论坛)

    2024-01-13 23:34:43
  • ASP.NET MVC把数据库中枚举项的数字转换成文字

    2024-01-16 07:35:39
  • 学习完全掌握纯CSS布局网页

    2008-05-28 17:14:00
  • PHP 获取远程网页内容的代码(fopen,curl已测)

    2024-05-05 09:17:59
  • python机器学习理论与实战(二)决策树

    2021-09-24 06:20:33
  • asp.net下使用DbProviderFactories的数据库操作类

    2024-01-16 15:34:02
  • mysql中profile的使用方法教程

    2024-01-16 02:28:52
  • js验证表单(form)中的单选(radio)值

    2008-03-18 13:23:00
  • 还不知道Anaconda是什么?读这一篇文章就够了

    2022-02-19 01:36:50
  • Python和Sublime整合过程图示

    2023-04-11 15:23:33
  • asp之家 网络编程 m.aspxhome.com