tf.transpose() is a function provided in TensorFlow. This function is used to transpose the input tensor.
Syntax: tf.transpose(input_tensor, perm, conjugate)
input_tensor: as the name suggests it is the tensor which is to be transposed.
perm: This parameters specifies the permutation according to which the input_tensor is to be transposed.
conjugate: This parameters is set to True if the input_tensor is of type complex.
array([[1, 5], [2, 6], [3, 7], [4, 8]])
Example 2: With using perm parameter:
When this parameter is passes the tensor is transposed along the given axis. In simple words it defines the output shape of the transposed tensor.
array([[[ 1, 4], [ 2, 5], [ 3, 6]], [[ 7, 10], [ 8, 11], [ 9, 12]], [[13, 16], [14, 17], [15, 18]], [[19, 22], [20, 23], [21, 24]]]) shape (4, 3, 2)
The shape is (4, 3, 2) because our perm was [0, 2, 1]. The following is the mapping from perm to input tensor shape.
0 => 4 2 => 3 1 => 2
Example 3: Now we will study the conjugate parameter
It is set to True when we have complex variables in our tensor.
array([[1 + 1j, 4 + 4j], [2 + 2j, 5 + 5j], [3 + 3j, 6 + 6j]])
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python - tensorflow.math.bessel_i1e() function
- Python - tensorflow.math.bessel_i1() function
- Python - tensorflow.math.bessel_i0e() function
- tensorflow.math.special.spence() function in Python
- tensorflow.math.special.fresnel_sin() function in Python
- tensorflow.math.special.fresnel_cos() function in Python
- tensorflow.math.special.expint() function in Python
- tensorflow.math.special.dawsn() function in Python
- tensorflow.math.atan2() function in Python
- Python | Classify Handwritten Digits with Tensorflow
- Introduction to TensorFlow
- Introduction to Tensor with Tensorflow
- Python | Tensorflow cos() method
- Linear Regression Using Tensorflow
- Python | Tensorflow nn.sigmoid()
- Python | Tensorflow nn.relu() and nn.leaky_relu()
- Python | Tensorflow nn.softplus()
- Python | Tensorflow nn.tanh()
- Python | Creating tensors using different functions in Tensorflow
- ML | Logistic Regression using Tensorflow
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.