网络编程
位置:首页>> 网络编程>> Python编程>> pytorch常用函数之torch.randn()解读

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

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

标签: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]]))

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

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com