mindspore.ops.BroadcastTo

class mindspore.ops.BroadcastTo(shape)[source]

Broadcasts input tensor to a given shape.

Refer to mindspore.ops.broadcast_to() for more details.

Supported Platforms:

Ascend GPU CPU

Examples

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