numpy.argmax()的理论平均用例运行时复杂度 [英] Theoretical average case runtime complexity of `numpy.argmax()`

查看:232
本文介绍了numpy.argmax()的理论平均用例运行时复杂度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看 numpy.argmax 函数的代码.我对 argmax 函数维护的 numpy 数据结构感到困惑.

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.

解决方案

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.

这篇关于numpy.argmax()的理论平均用例运行时复杂度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆