How is Argsort in Tensorflow?

How can I argue the 25 x 5 x 5 matrix (tensor) along the 2nd axis? Essentially, I'm looking for a tensor equivalent (function or methodology) for numpy argsort, for example. np.argsort(matrix, 2) .

+7
source share
2 answers

In your case, you can probably use top_k , which returns the highest k values. k may be a 1D vector defining the number of values ​​up to 'top' for measurements. In your case, if you want the second axis set by k=[0, 5, 0] to be able to do this.

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

I did not run it. Hope this helps

+9
source

For reference, tf.argsort is now supported in Tensorflow.

An example :

 import tensorflow as tf tensor = tf.constant( [ [8, 7, 11], [5, 3, 4], [17, 33, 23], ] ) arg_sort_op = tf.argsort(tensor, axis=-1) with tf.Session() as sess: out = sess.run(arg_sort_op) print(out) # [[1 0 2] # [1 2 0] # [0 2 1]] 
0
source

Source: https://habr.com/ru/post/1014628/


All Articles