broadcast_to¶
dragon.vm.tensorflow.
broadcast_to
(
input,
shape,
name=None
)[source]¶Broadcast input according to a given shape.
Length of
shape
could either be less or more than the number of input dimensions:a = tf.constant([[1], [2], [3]]) # Shape: (3, 1) -> (3, 2) print(tf.broadcast_to(a, shape=(3, 2))) print(tf.broadcast_to(a, shape=(2,))) # Equivalent print(tf.broadcast_to(a, shape=(-1, 2))) # Equivalent # Shape: (3,) -> (1, 3) -> (2, 3) b = tf.constant([1, 2, 3]) print(tf.broadcast_to(b, shape=(2, 3))) # Wrong remapping shape: (3,) -> (6,) # Only the dimension with size 1 could broadcast print(tf.broadcast_to(b, shape=(6,)))
- Parameters:
- input (dragon.Tensor) – The input tensor.
- shape (Sequence[Union[int, dragon.Tensor]]) – The output shape to broadcast to.
- name (str, optional) – The operation name.
- Returns:
dragon.Tensor – The output tensor.