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]])