Python API
broadcast_to
将张量广播至指定的形状。
inp (Tensor) – 输入张量。
Tensor
shape (Union[int, Iterable[int]]) – 目标形状。
Union
int
Iterable
输出张量。
例如:
import numpy as np from megengine import tensor import megengine.functional as F data = tensor(np.arange(0, 3, dtype=np.float32).reshape(3)) out = F.broadcast_to(data, (2, 3)) print(out.numpy())
输出:
[[0. 1. 2.] [0. 1. 2.]]