Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method to get k smallest elements from a tensor #43977

Open
digital-idiot opened this issue Oct 13, 2020 · 0 comments
Open

Method to get k smallest elements from a tensor #43977

digital-idiot opened this issue Oct 13, 2020 · 0 comments
Assignees
Labels
comp:ops OPs related issues stat:awaiting tensorflower Status - Awaiting response from tensorflower type:feature Feature requests

Comments

@digital-idiot
Copy link

digital-idiot commented Oct 13, 2020

tf.math.top_k only returns k largest elements from the input tensor along a specified axis. However, there is no direct way to obtain k smallest elements from a tensor. The equivalent method topk in pytorch has an bool flag largest to toggle the output from k largest elements to k smallest elements and vice versa. It would be useful to have similar option (or an alternative method like bottom_k) for this purpose so that hacky solution like the following can be avoided.

tf.negative(tf.math.top_k(tf.negative(A)))

Finding k minimum values can be potentially very useful in many cases especially for writing custom ops. This does not seem to be too hard to implement or drastically change the API.

System information

  • TensorFlow version: 2.3

Related discussion in Stackoverflow.

@digital-idiot digital-idiot added the type:feature Feature requests label Oct 13, 2020
@amahendrakar amahendrakar added the comp:ops OPs related issues label Oct 13, 2020
@jvishnuvardhan jvishnuvardhan added the stat:awaiting tensorflower Status - Awaiting response from tensorflower label Oct 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:ops OPs related issues stat:awaiting tensorflower Status - Awaiting response from tensorflower type:feature Feature requests
Projects
None yet
Development

No branches or pull requests

3 participants