當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python tensorflow.math.invert_permutation()用法及代碼示例

TensorFlow是Google設計的開源Python庫,用於開發機器學習模型和深度學習神經網絡。

invert_permutation()用於計算張量的反置換。

用法:tensorflow.math.invert_permutation( x, name)

參數:

  • x:它是一維張量。允許的dtype是int32和int64。張量值應在[0,4)範圍內。
  • name(optional):它定義了操作的名稱

返回值:它返回dtype的張量作為x。



範例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)

輸出:

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


範例2:本示例使用超出範圍的值。它將引發InvalidArgument錯誤

Python3

# Importing the libraray 
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)

輸出:

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]




相關用法


注:本文由純淨天空篩選整理自aman neekhara大神的英文原創作品 Python – tensorflow.math.invert_permutation()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。