python - 理论平均案例运行时复杂度为 `numpy.argmax()`

标签 python numpy data-structures max

我正在查看numpy.argmax函数的代码。我很困惑 numpyargmax 函数维护哪种数据结构。

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)。您迭代数组一次以找到最大值。

enter image description here

关于python - 理论平均案例运行时复杂度为 `numpy.argmax()`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63734910/

相关文章:

python - apache_beam.examples.wordcount 的输入

python - 通过加载训练有素的模型进行多重处理。 (通过Python3)

python - 如何用 Python 打开 bash session 并保持通信?

python - 为什么在给定分数矩阵时 numpy 行列式不返回分数?

c - 用于数据包缓冲区的适当数据结构

algorithm - 计算二维数组中 block 组的总数?

python - ipython笔记本清除所有代码

numpy - 在 Deepnote 中运行 ImageDataBunch 时出现问题

python - 运行 Holoview 和弦图示例时出错

algorithm - 使用 B-Tree 代替 Trie