tf.invert_permutation

tf.invert_permutation(x, name=None)

tf.math.invert_permutation(x, name=None)

TensorFlow目录总结

入参 / 出参含义取值范围
xA 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开始取值
nameA name for the operation (optional).例如:name = ‘invert_permutation’
ReturnsA 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]
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值