评价此页

torch.broadcast_to#

torch.broadcast_to(input, shape) Tensor#

input 广播到 shape。等同于调用 input.expand(shape)。有关详细信息,请参阅 expand()

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

  • shape (list, tuple, or torch.Size) – 新的形状。

示例

>>> x = torch.tensor([1, 2, 3])
>>> torch.broadcast_to(x, (3, 3))
tensor([[1, 2, 3],
        [1, 2, 3],
        [1, 2, 3]])