Theoretical average case runtime complexity of `numpy.argmax()`

删除回忆录丶 提交于 2021-01-28 05:44:08

问题


I was looking at the code of numpy.argmax function. I am confused which data structure numpy maintains for the argmax function.

https://numpy.org/doc/stable/reference/generated/numpy.argmax.html

Eventually, I want to know what is the theoretical average case running time complexity of numpy argmax function for primitive data types. Is it O(logN) or O(N) in the average case?

This may be a relevant question as well: Faster alternatives to numpy.argmax/argmin which is slow

Thanks in advance.


回答1:


Here is a performance analysis using benchit:

def m(x):
  return np.argmax(x)

in_ = [np.random.rand(n) for n in [10,100,1000,10000]]

As you can see it is O(N) as it should be. You iterate over array once to find the maximum.



来源:https://stackoverflow.com/questions/63734910/theoretical-average-case-runtime-complexity-of-numpy-argmax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!