tf.compat.v1.transpose
Stay organized with collections
Save and categorize content based on your preferences.
Transposes a
.
tf.compat.v1.transpose(
a, perm=None, name='transpose', conjugate=False
)
Permutes the dimensions according to perm
.
The returned tensor's dimension i will correspond to the input dimension
perm[i]
. If perm
is not given, it is set to (n-1...0), where n is
the rank of the input tensor. Hence, by default, this operation performs a
regular matrix transpose on 2-D input Tensors. If conjugate is True and
a.dtype
is either complex64
or complex128
then the values of a
are conjugated and transposed.
For example:
x = tf.constant([[1, 2, 3], [4, 5, 6]])
tf.transpose(x) # [[1, 4]
# [2, 5]
# [3, 6]]
# Equivalently
tf.transpose(x, perm=[1, 0]) # [[1, 4]
# [2, 5]
# [3, 6]]
# If x is complex, setting conjugate=True gives the conjugate transpose
x = tf.constant([[1 + 1j, 2 + 2j, 3 + 3j],
[4 + 4j, 5 + 5j, 6 + 6j]])
tf.transpose(x, conjugate=True) # [[1 - 1j, 4 - 4j],
# [2 - 2j, 5 - 5j],
# [3 - 3j, 6 - 6j]]
# 'perm' is more useful for n-dimensional tensors, for n > 2
x = tf.constant([[[ 1, 2, 3],
[ 4, 5, 6]],
[[ 7, 8, 9],
[10, 11, 12]]])
# Take the transpose of the matrices in dimension-0
# (this common operation has a shorthand `linalg.matrix_transpose`)
tf.transpose(x, perm=[0, 2, 1]) # [[[1, 4],
# [2, 5],
# [3, 6]],
# [[7, 10],
# [8, 11],
# [9, 12]]]
Args |
a
|
A Tensor .
|
perm
|
A permutation of the dimensions of a .
|
name
|
A name for the operation (optional).
|
conjugate
|
Optional bool. Setting it to True is mathematically equivalent
to tf.math.conj(tf.transpose(input)).
|
Returns |
A transposed Tensor .
|
In numpy
transposes are memory-efficient constant time operations as they
simply return a new view of the same data with adjusted strides
.
TensorFlow does not support strides, so transpose
returns a new tensor with
the items permuted.
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.compat.v1.transpose\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#L1873-L1958) |\n\nTransposes `a`. \n\n tf.compat.v1.transpose(\n a, perm=None, name='transpose', conjugate=False\n )\n\nPermutes the dimensions according to `perm`.\n\nThe returned tensor's dimension i will correspond to the input dimension\n`perm[i]`. If `perm` is not given, it is set to (n-1...0), where n is\nthe rank of the input tensor. Hence, by default, this operation performs a\nregular matrix transpose on 2-D input Tensors. If conjugate is True and\n`a.dtype` is either `complex64` or `complex128` then the values of `a`\nare conjugated and transposed.\n\n#### For example:\n\n x = tf.constant([[1, 2, 3], [4, 5, 6]])\n tf.transpose(x) # [[1, 4]\n # [2, 5]\n # [3, 6]]\n\n # Equivalently\n tf.transpose(x, perm=[1, 0]) # [[1, 4]\n # [2, 5]\n # [3, 6]]\n\n # If x is complex, setting conjugate=True gives the conjugate transpose\n x = tf.constant([[1 + 1j, 2 + 2j, 3 + 3j],\n [4 + 4j, 5 + 5j, 6 + 6j]])\n tf.transpose(x, conjugate=True) # [[1 - 1j, 4 - 4j],\n # [2 - 2j, 5 - 5j],\n # [3 - 3j, 6 - 6j]]\n\n # 'perm' is more useful for n-dimensional tensors, for n \u003e 2\n x = tf.constant([[[ 1, 2, 3],\n [ 4, 5, 6]],\n [[ 7, 8, 9],\n [10, 11, 12]]])\n\n # Take the transpose of the matrices in dimension-0\n # (this common operation has a shorthand `linalg.matrix_transpose`)\n tf.transpose(x, perm=[0, 2, 1]) # [[[1, 4],\n # [2, 5],\n # [3, 6]],\n # [[7, 10],\n # [8, 11],\n # [9, 12]]]\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------|--------------------------------------------------------------------------------------------------------|\n| `a` | A `Tensor`. |\n| `perm` | A permutation of the dimensions of `a`. |\n| `name` | A name for the operation (optional). |\n| `conjugate` | Optional bool. Setting it to `True` is mathematically equivalent to tf.math.conj(tf.transpose(input)). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A transposed `Tensor`. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nnumpy compatibility\n-------------------\n\n\u003cbr /\u003e\n\nIn `numpy` transposes are memory-efficient constant time operations as they\nsimply return a new view of the same data with adjusted `strides`.\n\nTensorFlow does not support strides, so `transpose` returns a new tensor with\nthe items permuted.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e"]]