|TensorFlow 1 version|
Broadcast an array for a compatible shape.
Compat aliases for migration
See Migration guide for more details.
tf.broadcast_to( input, shape, name=None )
Used in the notebooks
|Used in the guide||Used in the tutorials|
Broadcasting is the process of making arrays to have compatible shapes for arithmetic operations. Two shapes are compatible if for each dimension pair they are either equal or one of them is one. When trying to broadcast a Tensor to a shape, it starts with the trailing dimensions, and works its way forward.
x = tf.constant([1, 2, 3])
y = tf.broadcast_to(x, [3, 3])
[[1 2 3]
[1 2 3]
[1 2 3]], shape=(3, 3), dtype=int32)
In the above example, the input Tensor with the shape of
is broadcasted to output Tensor with shape of
When doing broadcasted operations such as multiplying a tensor by a scalar, broadcasting (usually) confers some time or space benefit, as the broadcasted tensor is never materialized.
broadcast_to does not carry with it any such benefits.
The newly-created tensor takes the full memory of the broadcasted
shape. (In a graph context,
broadcast_to might be fused to
subsequent operation and then be optimized away, however.)
||A name for the operation (optional).|