Numpy argsort - what is it doing?

后端 未结 9 2389
礼貌的吻别
礼貌的吻别 2020-11-28 19:15

Why is numpy giving this result:

x = numpy.array([1.48,1.41,0.0,0.1])
print x.argsort()

>[2 3 1 0]

when I\'d expect it to do this:

9条回答
  •  眼角桃花
    2020-11-28 19:29

    As the documentation says, argsort:

    Returns the indices that would sort an array.

    That means the first element of the argsort is the index of the element that should be sorted first, the second element is the index of the element that should be second, etc.

    What you seem to want is the rank order of the values, which is what is provided by scipy.stats.rankdata. Note that you need to think about what should happen if there are ties in the ranks.

提交回复
热议问题