tf.reverse
Stay organized with collections
Save and categorize content based on your preferences.
Reverses specific dimensions of a tensor.
tf.reverse(
tensor: Annotated[Any, TV_ReverseV2_T],
axis: Annotated[Any, TV_ReverseV2_Tidx],
name=None
) -> Annotated[Any, TV_ReverseV2_T]
Used in the notebooks
Given a tensor
, and a int32
tensor axis
representing the set of
dimensions of tensor
to reverse. This operation reverses each dimension
i
for which there exists j
s.t. axis[j] == i
.
tensor
can have up to 8 dimensions. The number of dimensions specified
in axis
may be 0 or more entries. If an index is specified more than
once, a InvalidArgument error is raised.
For example:
# tensor 't' is [[[[ 0, 1, 2, 3],
# [ 4, 5, 6, 7],
# [ 8, 9, 10, 11]],
# [[12, 13, 14, 15],
# [16, 17, 18, 19],
# [20, 21, 22, 23]]]]
# tensor 't' shape is [1, 2, 3, 4]
# 'dims' is [3] or 'dims' is [-1]
reverse(t, dims) ==> [[[[ 3, 2, 1, 0],
[ 7, 6, 5, 4],
[ 11, 10, 9, 8]],
[[15, 14, 13, 12],
[19, 18, 17, 16],
[23, 22, 21, 20]]]]
# 'dims' is '[1]' (or 'dims' is '[-3]')
reverse(t, dims) ==> [[[[12, 13, 14, 15],
[16, 17, 18, 19],
[20, 21, 22, 23]
[[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]]]]
# 'dims' is '[2]' (or 'dims' is '[-2]')
reverse(t, dims) ==> [[[[8, 9, 10, 11],
[4, 5, 6, 7],
[0, 1, 2, 3]]
[[20, 21, 22, 23],
[16, 17, 18, 19],
[12, 13, 14, 15]]]]
Args |
tensor
|
A Tensor . Must be one of the following types: uint8 , int8 , uint16 , int16 , int32 , uint32 , int64 , uint64 , bool , bfloat16 , half , float32 , float64 , complex64 , complex128 , string .
Up to 8-D.
|
axis
|
A Tensor . Must be one of the following types: int32 , int64 .
1-D. The indices of the dimensions to reverse. Must be in the range
[-rank(tensor), rank(tensor)) .
|
name
|
A name for the operation (optional).
|
Returns |
A Tensor . Has the same type as tensor .
|
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."],[],[],null,["# tf.reverse\n\n\u003cbr /\u003e\n\nReverses specific dimensions of a tensor.\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.manip.reverse`](https://www.tensorflow.org/api_docs/python/tf/reverse), [`tf.compat.v1.reverse`](https://www.tensorflow.org/api_docs/python/tf/reverse), [`tf.compat.v1.reverse_v2`](https://www.tensorflow.org/api_docs/python/tf/reverse)\n\n\u003cbr /\u003e\n\n tf.reverse(\n tensor: Annotated[Any, TV_ReverseV2_T],\n axis: Annotated[Any, TV_ReverseV2_Tidx],\n name=None\n ) -\u003e Annotated[Any, TV_ReverseV2_T]\n\n### Used in the notebooks\n\n| Used in the guide |\n|--------------------------------------------------------------------|\n| - [Ragged tensors](https://www.tensorflow.org/guide/ragged_tensor) |\n\nGiven a `tensor`, and a `int32` tensor `axis` representing the set of\ndimensions of `tensor` to reverse. This operation reverses each dimension\n`i` for which there exists `j` s.t. `axis[j] == i`.\n\n`tensor` can have up to 8 dimensions. The number of dimensions specified\nin `axis` may be 0 or more entries. If an index is specified more than\nonce, a InvalidArgument error is raised.\n\n#### For example:\n\n # tensor 't' is [[[[ 0, 1, 2, 3],\n # [ 4, 5, 6, 7],\n # [ 8, 9, 10, 11]],\n # [[12, 13, 14, 15],\n # [16, 17, 18, 19],\n # [20, 21, 22, 23]]]]\n # tensor 't' shape is [1, 2, 3, 4]\n\n # 'dims' is [3] or 'dims' is [-1]\n reverse(t, dims) ==\u003e [[[[ 3, 2, 1, 0],\n [ 7, 6, 5, 4],\n [ 11, 10, 9, 8]],\n [[15, 14, 13, 12],\n [19, 18, 17, 16],\n [23, 22, 21, 20]]]]\n\n # 'dims' is '[1]' (or 'dims' is '[-3]')\n reverse(t, dims) ==\u003e [[[[12, 13, 14, 15],\n [16, 17, 18, 19],\n [20, 21, 22, 23]\n [[ 0, 1, 2, 3],\n [ 4, 5, 6, 7],\n [ 8, 9, 10, 11]]]]\n\n # 'dims' is '[2]' (or 'dims' is '[-2]')\n reverse(t, dims) ==\u003e [[[[8, 9, 10, 11],\n [4, 5, 6, 7],\n [0, 1, 2, 3]]\n [[20, 21, 22, 23],\n [16, 17, 18, 19],\n [12, 13, 14, 15]]]]\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `tensor` | A `Tensor`. Must be one of the following types: `uint8`, `int8`, `uint16`, `int16`, `int32`, `uint32`, `int64`, `uint64`, `bool`, `bfloat16`, `half`, `float32`, `float64`, `complex64`, `complex128`, `string`. Up to 8-D. |\n| `axis` | A `Tensor`. Must be one of the following types: `int32`, `int64`. 1-D. The indices of the dimensions to reverse. Must be in the range `[-rank(tensor), rank(tensor))`. |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `Tensor`. Has the same type as `tensor`. ||\n\n\u003cbr /\u003e"]]