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