BroadcastTo

public final class BroadcastTo

Broadcast an array for a compatible shape.

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.

For example,

>>> x = tf.constant([1, 2, 3]) >>> y = tf.broadcast_to(x, [3, 3]) >>> print(y) tf.Tensor( [[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 `[1, 3]` is broadcasted to output Tensor with shape of `[3, 3]`.

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.

However, `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.)

Constants

String OP_NAME The name of this op, as known by TensorFlow core engine

Public Methods

Output<T>
asOutput()
Returns the symbolic handle of the tensor.
static <T extends TType> BroadcastTo<T>
create(Scope scope, Operand<T> input, Operand<? extends TNumber> shape)
Factory method to create a class wrapping a new BroadcastTo operation.
Output<T>
output()
A Tensor.

Inherited Methods

org.tensorflow.op.RawOp
final boolean
equals(Object obj)
final int
Operation
op()
Return this unit of computation as a single Operation.
final String
boolean
equals(Object arg0)
final Class<?>
getClass()
int
hashCode()
final void
notify()
final void
notifyAll()
String
toString()
final void
wait(long arg0, int arg1)
final void
wait(long arg0)
final void
wait()
org.tensorflow.op.Op
abstract ExecutionEnvironment
env()
Return the execution environment this op was created in.
abstract Operation
op()
Return this unit of computation as a single Operation.
org.tensorflow.Operand
abstract Output<T>
asOutput()
Returns the symbolic handle of the tensor.
abstract T
asTensor()
Returns the tensor at this operand.
abstract Shape
shape()
Returns the (possibly partially known) shape of the tensor referred to by the Output of this operand.
abstract Class<T>
type()
Returns the tensor type of this operand
org.tensorflow.ndarray.Shaped
abstract int
rank()
abstract Shape
shape()
abstract long
size()
Computes and returns the total size of this container, in number of values.

Constants

public static final String OP_NAME

The name of this op, as known by TensorFlow core engine

Constant Value: "BroadcastTo"

Public Methods

public Output<T> asOutput ()

Returns the symbolic handle of the tensor.

Inputs to TensorFlow operations are outputs of another TensorFlow operation. This method is used to obtain a symbolic handle that represents the computation of the input.

public static BroadcastTo<T> create (Scope scope, Operand<T> input, Operand<? extends TNumber> shape)

Factory method to create a class wrapping a new BroadcastTo operation.

Parameters
scope current scope
input A Tensor to broadcast.
shape An 1-D `int` Tensor. The shape of the desired output.
Returns
  • a new instance of BroadcastTo

public Output<T> output ()

A Tensor.