評價此頁

torch.broadcast_to#

torch.broadcast_to(input, shape) Tensor#

input 廣播到 shape 指定的形狀。等同於呼叫 input.expand(shape)。有關詳細資訊,請參閱 expand()

引數
  • input (Tensor) – 輸入張量。

  • shape (list, tuple, 或 torch.Size) – 新的形狀。

示例

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