Faster alternatives to numpy.argmax/argmin which is slow

前端 未结 3 907
深忆病人
深忆病人 2020-11-29 11:53

I am using a lot of argmin and argmax in Python.

Unfortunately, the function is very slow.

I have done some searching around, and the best I can find is here

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-29 12:06

    Can you post some code? Here is the result on my pc:

    x = np.random.rand(10000)
    %timeit np.max(x)
    %timeit np.argmax(x)
    

    output:

    100000 loops, best of 3: 7.43 µs per loop
    100000 loops, best of 3: 11.5 µs per loop
    

提交回复
热议问题