Wednesday, June 17, 2026
HomeLanguagesPython – tensorflow.math.invert_permutation()

Python – tensorflow.math.invert_permutation()

TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. 

invert_permutation() is used to compute inverse permutation of a tensor.

Syntax: tensorflow.math.invert_permutation( x, name)

Parameters:

  • x: It is a 1-D tensor. Allowed dtypes are int32 and int64. Tensor values should be in range [0, 4).
  • name(optional): It defines the name of the operation

Returns: It returns a tensor of dtype as x.

Example 1:

Python3




# importing the library
import tensorflow as tf
 
# Initializing the input tensor
a = tf.constant([1, 2, 3, 0], dtype = tf.int64)
 
# Printing the input tensor
print('a: ', a)
 
# Calculating the result
res = tf.math.invert_permutation(a)
 
# Printing the result
print('Result: ', res)


Output:

a:  tf.Tensor([1 2 3 0], shape=(4, ), dtype=int64)
Result:  tf.Tensor([3 0 1 2], shape=(4, ), dtype=int64)

Example 2: This example uses out of range value. It will raise InvalidArgument Error

Python3




# Importing the library
import tensorflow as tf
 
# Initializing the input tensor
a = tf.constant([1, 2, 3, 4], dtype = tf.int64)
 
# Printing the input tensor
print('a: ', a)
 
# Calculating the result
res = tf.math.invert_permutation(a)
 
# Printing the result
print('Result: ', res)


Output:

a:  tf.Tensor([1 2 3 4], shape=(4, ), dtype=int64)

---------------------------------------------------------------------------

InvalidArgumentError                      Traceback (most recent call last)

 in ()
      9 
     10 # Calculating the result
---> 11 res = tf.math.invert_permutation(a)
     12 
     13 # Printing the result

2 frames

/usr/local/lib/python3.6/dist-packages/six.py in raise_from(value, from_value)

InvalidArgumentError: 4 is not between 0 and 4 [Op:InvertPermutation]
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12014 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS