Stay organized with collections
Save and categorize content based on your preferences.
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
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.)
Args:
-
scope: A
Scope
object
-
input: A
Tensor
to broadcast.
-
shape: An 1-D
int
Tensor
. The shape of the desired output.
Returns:
Public attributes
Public functions
node
::tensorflow::Node * node() const
operator::tensorflow::Input() const
operator::tensorflow::Output
operator::tensorflow::Output() const
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2021-08-16 UTC.
[null,null,["Last updated 2021-08-16 UTC."],[],[],null,["# tensorflow::ops::BroadcastTo Class Reference\n\ntensorflow::\nops::\nBroadcastTo\n==============================\n\n`\n#include \u003carray_ops.h\u003e\n`\n\n\nBroadcast an array for a compatible shape.\n\nSummary\n-------\n\n\nBroadcasting 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\n[Tensor](/versions/r2.6/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor)\nto a shape, it starts with the trailing dimensions, and works its way forward.\n\n\nFor example,\n\n\nx = 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)\n\n\nIn the above example, the input\n[Tensor](/versions/r2.6/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor)\nwith the shape of\n`\n[1, 3]\n`\nis broadcasted to output\n[Tensor](/versions/r2.6/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor)\nwith shape of\n`\n[3, 3]\n`\n.\n\n\nWhen 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.\n\n\nHowever,\n`\nbroadcast_to\n`\ndoes not carry with it any such benefits. The newly-created tensor takes the full memory of the broadcasted shape. (In a graph context,\n`\nbroadcast_to\n`\nmight be fused to subsequent operation and then be optimized away, however.)\n\n\nArgs:\n\n- scope: A [Scope](/versions/r2.6/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope) object\n- input: A [Tensor](/versions/r2.6/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) to broadcast.\n- shape: An 1-D `\n int\n ` [Tensor](/versions/r2.6/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) . The shape of the desired output.\n\n\u003cbr /\u003e\n\n\nReturns:\n\n- `\n `[Output](/versions/r2.6/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output)`\n ` : A [Tensor](/versions/r2.6/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor) .\n\n\u003cbr /\u003e\n\n| ### Constructors and Destructors ||\n|---|---|\n| ` `[BroadcastTo](#classtensorflow_1_1ops_1_1_broadcast_to_1a37bf1f8b63e588def9b3805017209ee6)` (const :: `[tensorflow::Scope](/versions/r2.6/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, :: `[tensorflow::Input](/versions/r2.6/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` input, :: `[tensorflow::Input](/versions/r2.6/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` shape) ` ||\n\n| ### Public attributes ||\n|------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------|\n| ` `[operation](#classtensorflow_1_1ops_1_1_broadcast_to_1abb152ff71cda1cf3af84a7c656faac03)` ` | ` `[Operation](/versions/r2.6/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation)` ` |\n| ` `[output](#classtensorflow_1_1ops_1_1_broadcast_to_1aaa451e1fc17fe438aa744a2880efca62)` ` | ` :: `[tensorflow::Output](/versions/r2.6/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output)` ` |\n\n| ### Public functions ||\n|----------------------------------------------------------------------------------------------------------------------------|--------------------------|\n| ` `[node](#classtensorflow_1_1ops_1_1_broadcast_to_1a2c429236acfd549d2252190a63a446f0)` () const ` | ` ::tensorflow::Node * ` |\n| ` `[operator::tensorflow::Input](#classtensorflow_1_1ops_1_1_broadcast_to_1a21be2705c2eba98f1cf7560295561b58)` () const ` | ` ` |\n| ` `[operator::tensorflow::Output](#classtensorflow_1_1ops_1_1_broadcast_to_1a43222f4482f5ccb868548380633ce7f5)` () const ` | ` ` |\n\nPublic attributes\n-----------------\n\n### operation\n\n```text\nOperation operation\n``` \n\n### output\n\n```text\n::tensorflow::Output output\n``` \n\nPublic functions\n----------------\n\n### BroadcastTo\n\n```gdscript\n BroadcastTo(\n const ::tensorflow::Scope & scope,\n ::tensorflow::Input input,\n ::tensorflow::Input shape\n)\n``` \n\n### node\n\n```gdscript\n::tensorflow::Node * node() const \n``` \n\n### operator::tensorflow::Input\n\n```gdscript\n operator::tensorflow::Input() const \n``` \n\n### operator::tensorflow::Output\n\n```gdscript\n operator::tensorflow::Output() const \n```"]]