tf.repeat
Stay organized with collections
Save and categorize content based on your preferences.
Repeat elements of input
.
tf.repeat(
input, repeats, axis=None, name=None
)
Used in the notebooks
See also tf.concat
, tf.stack
, tf.tile
.
Args |
input
|
An N -dimensional Tensor.
|
repeats
|
An 1-D int Tensor. The number of repetitions for each element.
repeats is broadcasted to fit the shape of the given axis. len(repeats)
must equal input.shape[axis] if axis is not None.
|
axis
|
An int. The axis along which to repeat values. By default, (axis=None),
use the flattened input array, and return a flat output array.
|
name
|
A name for the operation.
|
Returns |
A Tensor which has the same shape as input , except along the given axis.
If axis is None then the output array is flattened to match the flattened
input array.
|
Example usage:
repeat(['a', 'b', 'c'], repeats=[3, 0, 2], axis=0)
<tf.Tensor: shape=(5,), dtype=string,
numpy=array([b'a', b'a', b'a', b'c', b'c'], dtype=object)>
repeat([[1, 2], [3, 4]], repeats=[2, 3], axis=0)
<tf.Tensor: shape=(5, 2), dtype=int32, numpy=
array([[1, 2],
[1, 2],
[3, 4],
[3, 4],
[3, 4]], dtype=int32)>
repeat([[1, 2], [3, 4]], repeats=[2, 3], axis=1)
<tf.Tensor: shape=(2, 5), dtype=int32, numpy=
array([[1, 1, 2, 2, 2],
[3, 3, 4, 4, 4]], dtype=int32)>
repeat(3, repeats=4)
<tf.Tensor: shape=(4,), dtype=int32, numpy=array([3, 3, 3, 3], dtype=int32)>
repeat([[1,2], [3,4]], repeats=2)
<tf.Tensor: shape=(8,), dtype=int32,
numpy=array([1, 1, 2, 2, 3, 3, 4, 4], dtype=int32)>
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 2024-04-26 UTC.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf.repeat\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/array_ops.py#L6592-L6643) |\n\nRepeat elements of `input`.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.repeat`](https://www.tensorflow.org/api_docs/python/tf/repeat)\n\n\u003cbr /\u003e\n\n tf.repeat(\n input, repeats, axis=None, name=None\n )\n\n### Used in the notebooks\n\n| Used in the tutorials |\n|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| - [Transfer learning with YAMNet for environmental sound classification](https://www.tensorflow.org/tutorials/audio/transfer_learning_audio) - [Parametrized Quantum Circuits for Reinforcement Learning](https://www.tensorflow.org/quantum/tutorials/quantum_reinforcement_learning) - [Recommend movies for users with TensorFlow Ranking](https://www.tensorflow.org/ranking/tutorials/quickstart) - [Listwise ranking](https://www.tensorflow.org/recommenders/examples/listwise_ranking) |\n\nSee also [`tf.concat`](../tf/concat), [`tf.stack`](../tf/stack), [`tf.tile`](../tf/tile).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `input` | An `N`-dimensional Tensor. |\n| `repeats` | An 1-D `int` Tensor. The number of repetitions for each element. repeats is broadcasted to fit the shape of the given axis. `len(repeats)` must equal `input.shape[axis]` if axis is not None. |\n| `axis` | An int. The axis along which to repeat values. By default, (axis=None), use the flattened input array, and return a flat output array. |\n| `name` | A name for the operation. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A Tensor which has the same shape as `input`, except along the given axis. If axis is None then the output array is flattened to match the flattened input array. ||\n\n\u003cbr /\u003e\n\n#### Example usage:\n\n repeat(['a', 'b', 'c'], repeats=[3, 0, 2], axis=0)\n \u003ctf.Tensor: shape=(5,), dtype=string,\n numpy=array([b'a', b'a', b'a', b'c', b'c'], dtype=object)\u003e\n\n repeat([[1, 2], [3, 4]], repeats=[2, 3], axis=0)\n \u003ctf.Tensor: shape=(5, 2), dtype=int32, numpy=\n array([[1, 2],\n [1, 2],\n [3, 4],\n [3, 4],\n [3, 4]], dtype=int32)\u003e\n\n repeat([[1, 2], [3, 4]], repeats=[2, 3], axis=1)\n \u003ctf.Tensor: shape=(2, 5), dtype=int32, numpy=\n array([[1, 1, 2, 2, 2],\n [3, 3, 4, 4, 4]], dtype=int32)\u003e\n\n repeat(3, repeats=4)\n \u003ctf.Tensor: shape=(4,), dtype=int32, numpy=array([3, 3, 3, 3], dtype=int32)\u003e\n\n repeat([[1,2], [3,4]], repeats=2)\n \u003ctf.Tensor: shape=(8,), dtype=int32,\n numpy=array([1, 1, 2, 2, 3, 3, 4, 4], dtype=int32)\u003e"]]