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