在Python中获取数组中数字的升序 [英] Get ascending order of numbers in array in python

查看:89
本文介绍了在Python中获取数组中数字的升序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有一些数字的Numpy数组,我想订购商品的升序.

I have a Numpy array with some numbers and I would like to get order the items ascending order.

例如,我有一个列表:

[4, 25, 100, 4, 50]

我想使用一个函数来获取此信息:

And I would like to use a function to get this:

[1, 2, 4, 1, 3]

任何想法如何做到这一点?

Any ideas how to do this?

推荐答案

通过pandas有一种便捷的方法:

There is a convenient method via pandas:

import pandas as pd

lst = [4, 25, 100, 4, 50]
res = pd.factorize(lst, sort=True)[0] + 1

# [1 2 4 1 3]

这篇关于在Python中获取数组中数字的升序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆