torch.t

torch.t(input) Tensor

期望 input 是一个最多二维的张量,并交换其第0维和第1维。

0维和1维张量保持不变并返回。当输入为二维张量时,这相当于执行transpose(input, 0, 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()

本页目录