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()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。