我正在查看numpy.argmax
函数的代码。我很困惑 numpy
为 argmax
函数维护哪种数据结构。
https://numpy.org/doc/stable/reference/generated/numpy.argmax.html
最终,我想知道原始数据类型的 numpy argmax
函数的理论平均情况运行时间复杂度是多少。一般情况下是O(logN)
还是O(N)
?
这也可能是一个相关问题:Faster alternatives to numpy.argmax/argmin which is slow
提前致谢。
最佳答案
这是使用 benchit
进行的性能分析:
def m(x):
return np.argmax(x)
in_ = [np.random.rand(n) for n in [10,100,1000,10000]]
如您所见,它应该是O(N)
。您迭代数组一次以找到最大值。
关于python - 理论平均案例运行时复杂度为 `numpy.argmax()`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63734910/