Shortcuts

torch.broadcast_tensors

torch.broadcast_tensors(*tensors) List of Tensors[源代码]

根据广播语义广播给定的张量。

Parameters

*tensors – 任意数量的相同类型的张量

警告

广播张量的多个元素可能引用同一个内存位置。因此,就地操作(特别是那些向量化的操作)可能会导致不正确的行为。如果需要对张量进行写操作,请先克隆它们。

示例:

>>> x = torch.arange(3).view(1, 3)
>>> y = torch.arange(2).view(2, 1)
>>> a, b = torch.broadcast_tensors(x, y)
>>> a.size()
torch.Size([2, 3])
>>> a
tensor([[0, 1, 2],
        [0, 1, 2]])