tf.invert_permutation(x, name=None)
tf.math.invert_permutation(x, name=None)
TensorFlow目录总结
入参 / 出参 | 含义 | 取值范围 |
---|---|---|
x | A Tensor . Must be one of the following types: int32 , int64 . 1-D. | 其中取值【i】的范围:y[x[i]] = i for i in [0, 1, …, len(x) - 1]; 取值不可重复; 必须从0开始取值 |
name | A name for the operation (optional). | 例如:name = ‘invert_permutation’ |
Returns | A Tensor . Has the same type as x . |
tf.invert_permutation(x, name=None) 置换x数据与索引的关系
tensor x is [3, 4, 0, 2, 1]
invert_permutation(x) ==> [2, 4, 3, 0, 1]
具体使用例如
import tensorflow as tf
# tensorflow 1.14.0
x = [1, 2, 4, 5, 3, 0
]
a = tf.math.invert_permutation(x)
with tf.compat.v1.Session() as sess:print("x:\n", x)print('tf.math.invert_permutation(x):\n', a)print('tf.math.invert_permutation(x).run():\n', sess.run(a))
输出结果
x:[1, 2, 4, 5, 3, 0]
tf.math.invert_permutation(x):Tensor("InvertPermutation:0", shape=(6,), dtype=int32)
tf.math.invert_permutation(x).run():[5 0 1 4 2 3]