How do you sort scores while retaining sample identities?
argsort returns the indices that sort an array. Apply those indices to sample identifiers to keep them aligned.
numpy.argsort in practice
For scores 8, 3 and 8, a stable sort preserves the arrival order of the tie. Add a time key if ties have a different business rule.
import numpy as np
np.argsort([8,3,8], kind='stable')Result [1, 0, 2]
中文
怎样按分数排序又保留样本身份?
argsort 输出能把数值排好序的索引,可把相同顺序应用到样本编号。
numpy.argsort 算例
三人分数为 8、3、8,稳定排序使两位同分者保留原先顺序。若同分要按时间打破,还需将时间纳入排序规则。
import numpy as np
np.argsort([8,3,8], kind='stable')结果 [1, 0, 2]