如何在Tensorflow中进行Argsort? [英] How to Argsort in Tensorflow?

查看:449
本文介绍了如何在Tensorflow中进行Argsort?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何沿第二轴对25 x 5 x 5矩阵(张量)进行精算?本质上,我正在寻找与numpy的argsort等效的张量流(函数或方法),例如np.argsort(matrix, 2).

How can I argsort a 25 x 5 x 5 matrix (tensor) along the 2nd axis? Essentially, I am looking for tensorflow's equivalent (function or methodology) to numpy's argsort, e.g. np.argsort(matrix, 2).

推荐答案

在您的情况下,您可以使用top_k,它返回最高的k值. k可以是一维矢量,定义每个维顶部"有多少个值.在您的情况下,如果要设置第二个轴k=[0, 5, 0],可以这样做.

In your case you could probably use top_k which returns the highest k values. k can be a 1D vector defining how many values to 'top' per dimensions. In your case, if you want the second axis set k=[0, 5, 0] might do it.

tf.nn.top_k(matrix, k=[0,5,0], sorted=True)

我没有运行它. 希望对您有帮助

I didn't run it tho. Hope this helps

这篇关于如何在Tensorflow中进行Argsort?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆