mindspore.ops.BroadcastTo

class mindspore.ops.BroadcastTo(shape)[源代码]

将输入shape广播到目标shape。

更多细节请参考 mindspore.ops.broadcast_to()

支持平台:

Ascend GPU CPU

样例:

>>> shape = (2, 3)
>>> x = Tensor(np.array([1, 2, 3]).astype(np.float32))
>>> output = ops.BroadcastTo(shape=shape)(x)
>>> print(output)
[[1. 2. 3.]
 [1. 2. 3.]]
>>>
>>> shape = (-1, 2)
>>> x = Tensor(np.array([[1], [2]]).astype(np.float32))
>>> output = ops.BroadcastTo(shape=shape)(x)
>>> print(output)
[[1. 1.]
 [2. 2.]]