【发布时间】:2017-09-08 23:36:57
【问题描述】:
Python/NumPy 中的三个“all”方法有什么区别?性能差异的原因是什么? ndarray.all() 真的是三者中最快的吗?
这是我运行的计时测试:
In [59]: a = np.full(100000, True, dtype=bool)
In [60]: timeit a.all()
The slowest run took 5.40 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 5.24 µs per loop
In [61]: timeit all(a)
1000 loops, best of 3: 1.34 ms per loop
In [62]: timeit np.all(a)
The slowest run took 5.54 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 6.41 µs per loop
【问题讨论】:
标签: python performance numpy