torch.broadcast_to

torch.broadcast_to(input, shape) Tensor

input广播到形状shape。这等同于调用input.expand(shape)。详情请参阅expand()

参数
  • input (Tensor) – 需要输入的张量。

  • shape(列表、元组或torch.Size)- 新的形状。

示例:

>>> x = torch.tensor([1, 2, 3])
>>> torch.broadcast_to(x, (3, 3))
tensor([[1, 2, 3],
        [1, 2, 3],
        [1, 2, 3]])
本页目录