Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
argmin() and argsort()
#5
(Nov-13-2017, 07:13 PM)DeaD_EyE Wrote:
(Nov-13-2017, 10:16 AM)PythonNewbie Wrote: I noticed that argsort()[:1] returns an array, while argmin() returns a scalar.

indx_argmin() returns an integer.
x.argsort() returns an array and then you're accessing a slice with [:k] which still returns an array.

Right, but what I am trying to do is select the indices of the k smallest numbers instead of the index of the smallest number as a generalization. I wanted to test the general function argsort()[:k] by putting k = 1 and compare the results to that of argmin(), but the results were different. Why? and how can I fix it?

(Nov-13-2017, 05:46 PM)Larz60+ Wrote: you can get the max of a list with:
max(x)

But I don't want the max of a list. I want the indices of the k smallest numbers in an array.
Reply


Messages In This Thread
argmin() and argsort() - by PythonNewbie - Nov-13-2017, 10:16 AM
RE: argmin() and argsort() - by PythonNewbie - Nov-13-2017, 05:29 PM
RE: argmin() and argsort() - by Larz60+ - Nov-13-2017, 05:46 PM
RE: argmin() and argsort() - by DeaD_EyE - Nov-13-2017, 07:13 PM
RE: argmin() and argsort() - by PythonNewbie - Nov-14-2017, 09:05 PM
RE: argmin() and argsort() - by Larz60+ - Nov-14-2017, 10:40 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020