Pytorch官方文档(七)翻译版本

Pytorch官方文档(七)翻译版本

torch.t

作用:

  • 矩阵转置。

参数:

  1. input,输入的Tensor。

例子:

>>> x = torch.randn(())
>>> x
tensor(0.1995)
>>> torch.t(x)
tensor(0.1995)
>>> x = torch.randn(3)
>>> x
tensor([ 2.4320, -0.4608,  0.7702])
>>> torch.t(x)
tensor([.2.4320,.-0.4608,..0.7702])
>>> x = torch.randn(2, 3)
>>> x
tensor([[ 0.4875,  0.9158, -0.5872],
        [ 0.3938, -0.6929,  0.6932]])
>>> torch.t(x)
tensor([[ 0.4875,  0.3938],
        [ 0.9158, -0.6929],
        [-0.5872,  0.6932]])

torch.transpose

作用:

  • 交换指定的维度。

参数:

  1. input,输入的Tensor。
  2. dim0,第一个要交换的维度。
  3. dim1,第二个要交换的维度。

例子:

>>> x = torch.randn(2, 3)
>>> x
tensor([[ 1.0028, -0.9893,  0.5809],
        [-0.1669,  0.7299,  0.4942]])
>>> torch.transpose(x, 0, 1)
tensor([[ 1.0028, -0.1669],
        [-0.9893,  0.7299],
        [ 0.5809,  0.4942]])
>>> x = torch.randn(2, 3, 1)
>>> x
tensor([[[-0.6987],
         [-1.5592],
         [-1.3666]],
        [[-0.4368],
         [ 0.1533],
         [ 0.0405]]]) # (2, 3, 1)
>>> torch.transpose(x, 0, 2)
 tensor([[[-0.6987, -0.4368],
          [-1.5592,  0.1533],
          [-1.3666,  0.0405]]]) # (1, 3, 2)

torch.where

作用:

  • 条件筛选Tensor1内的值,不符合的位置用Tensor2的值来替换。

参数:

  1. condition,条件表达式。
  2. x,备选Tensor1。
  3. y,备选Tensor2。

例子:

>>> x = torch.randn(3, 2)
>>> y = torch.ones(3, 2)
>>> x
tensor([[-0.4620,  0.3139],
        [ 0.3898, -0.7197],
        [ 0.0478, -0.1657]])
>>> torch.where(x > 0, x, y)
tensor([[ 1.0000,  0.3139],
        [ 0.3898,  1.0000],
        [ 0.0478,  1.0000]])
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值