torch.broadcast_to¶
- torch.broadcast_to(input, shape) Tensor ¶
將
input
廣播 (broadcast) 到shape
的形狀。等同於呼叫input.expand(shape)
。詳細資訊請參閱expand()
。- 參數
input (Tensor) – 輸入張量 (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]])