我在上面建议了时间,这是我的结果。
首先,功能:
def f(seq): # http://stackoverflow.com/questions/3382352/equivalent-of-numpy-argsort-in-basic-python/3383106#3383106 #non-lambda version by Tony Veijalainen return [i for (v, i) in sorted((v, i) for (i, v) in enumerate(seq))]def g(seq): # http://stackoverflow.com/questions/3382352/equivalent-of-numpy-argsort-in-basic-python/3383106#3383106 #lambda version by Tony Veijalainen return [x for x,y in sorted(enumerate(seq), key = lambda x: x[1])]def h(seq): #http://stackoverflow.com/questions/3382352/equivalent-of-numpy-argsort-in-basic-python/3382369#3382369 #by unutbu return sorted(range(len(seq)), key=seq.__getitem__)
现在,IPython会话:
In [16]: seq = rand(10000).tolist()In [17]: %timeit f(seq)100 loops, best of 3: 10.5 ms per loopIn [18]: %timeit g(seq)100 loops, best of 3: 8.83 ms per loopIn [19]: %timeit h(seq)100 loops, best of 3: 6.44 ms per loop
第一次世界大战
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)