torch.functional.broadcast_tensors#
- torch.functional.broadcast_tensors(*tensors) List of Tensors[source]#
根據 廣播語義 廣播給定的張量。
- 引數
*tensors – 任意數量的相同型別的張量
警告
廣播張量的多個元素可能引用同一塊記憶體位置。因此,原地操作(尤其是向量化操作)可能導致不正確的行為。如果您需要寫入張量,請先克隆它們。
示例
>>> x = torch.arange(3).view(1, 3) >>> y = torch.arange(2).view(2, 1) >>> a, b = torch.broadcast_tensors(x, y) >>> a.size() torch.Size([2, 3]) >>> a tensor([[0, 1, 2], [0, 1, 2]])