def argsortdup(a1):
    sorted = sort(a1)
ranked = []
for item in a1:
    ranked.append(sorted.searchsorted(item))
return array(ranked)
a3 = argsortdup(a2)
a2
a3
Ranking of numpy array with possible duplicates