# tensorflow::ops::BroadcastTo Class Reference

# tensorflow::
ops::
BroadcastTo

`
#include <array_ops.h>
`


Broadcast an array for a compatible shape.

## Summary


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](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_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](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor)
with the shape of
`
[1, 3]
`
is broadcasted to output
[Tensor](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_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.)


Args:

- scope: A [Scope](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope) object
- input: A [Tensor](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) to broadcast.
- shape: An 1-D `
  int
  ` [Tensor](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) . The shape of the desired output.

<br />


Returns:

- `
  https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output
  ` : A [Tensor](https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) .

<br />

| ### Constructors and Destructors ||
|---|---|
| ` https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/broadcast-to#classtensorflow_1_1ops_1_1_broadcast_to_1a37bf1f8b63e588def9b3805017209ee6 (const :: https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope & scope, :: https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input input, :: https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input shape) ` ||

| ### Public attributes ||
|---|---|
| ` https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/broadcast-to#classtensorflow_1_1ops_1_1_broadcast_to_1abb152ff71cda1cf3af84a7c656faac03 ` | ` https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation ` |
| ` https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/broadcast-to#classtensorflow_1_1ops_1_1_broadcast_to_1aaa451e1fc17fe438aa744a2880efca62 ` | ` :: https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output ` |

| ### Public functions ||
|---|---|
| ` https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/broadcast-to#classtensorflow_1_1ops_1_1_broadcast_to_1a2c429236acfd549d2252190a63a446f0 () const ` | ` ::tensorflow::Node * ` |
| ` https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/broadcast-to#classtensorflow_1_1ops_1_1_broadcast_to_1a21be2705c2eba98f1cf7560295561b58 () const ` | ` ` |
| ` https://www.tensorflow.org/versions/r2.5/api_docs/cc/class/tensorflow/ops/broadcast-to#classtensorflow_1_1ops_1_1_broadcast_to_1a43222f4482f5ccb868548380633ce7f5 () const ` | ` ` |

## Public attributes

### operation

```
Operation operation
```

### output

```
::tensorflow::Output output
```

## Public functions

### BroadcastTo

```
 BroadcastTo(
  const ::tensorflow::Scope & scope,
  ::tensorflow::Input input,
  ::tensorflow::Input shape
)
```

### node

```
::tensorflow::Node * node() const 
```

### operator::tensorflow::Input

```
 operator::tensorflow::Input() const 
```

### operator::tensorflow::Output

```
 operator::tensorflow::Output() const 
```