天道酬勤,学无止境

张量排序

张量排序

目录OutlineSort/argsort一维二维Top_kTop_oneTop-k accuracy示例OutlineSort/argsortTopkTop-5 Acc.Sort/argsort一维import tensorflow as tfa = tf.random.shuffle(tf.range(5)) a<tf.Tensor: id=59, shape=(5,), dtype=int32, numpy=array([4, 0, 3, 2, 1], dtype=int32)>tf.sort(a, direction='DESCENDING')<tf.Tensor: id=69, shape=(5,), dtype=int32, numpy=array([4, 3, 2, 1, 0], dtype=int32)># 返回索引 tf.argsort(a, direction='DESCENDING')<tf.Tensor: id=81, shape=(5,), dtype=int32, numpy=array([0, 2, 3, 4, 1], dtype=int32)>idx = tf.argsort(a, direction='DESCENDING') tf.gather(a, idx)<tf.Tensor: id=94, shape=(5,), dtype=int32

2021-04-19 19:49:51    分类:博客    张量排序