索引numpy中的每个值,其中重复值具有相同的索引

时间:2019-09-07 20:31:01

标签: python numpy sorting indexing

我下面有numpy数组

import numpy as np
x = np.array(['i123', 'i314', 'i123', 'i543','i2341'])

对该数组执行排序操作

x_sort = np.sort(x)

print(x_sort)
['i123' 'i123' 'i2341' 'i314' 'i543']

现在我想要一个以以下方式表示 x_sort 索引的数组

[0, 0, 1, 2, 3]

其中0代表“ i123”,1代表“ i234”,依此类推。

任何人都可以使用numpy来帮助我以最快的方式实现这一目标,因为我的数据集包含数百万条此类记录。

0 个答案:

没有答案