[Numpy-discussion] all elements equal

Keith Goodman kwgoodman@gmail....
Mon Mar 5 13:44:38 CST 2012


On Mon, Mar 5, 2012 at 11:36 AM,  <josef.pktd@gmail.com> wrote:
> How about numpy.ptp, to follow this line? I would expect it's single
> pass, but wouldn't short circuit compared to cython of Keith

I[1] a = np.ones(100000)
I[2] timeit (a == a[0]).all()
1000 loops, best of 3: 203 us per loop
I[3] timeit a.min() == a.max()
10000 loops, best of 3: 106 us per loop
I[4] timeit np.ptp(a)
10000 loops, best of 3: 106 us per loop

I[5] a[1] = 9
I[6] timeit (a == a[0]).all()
10000 loops, best of 3: 89.7 us per loop
I[7] timeit a.min() == a.max()
10000 loops, best of 3: 102 us per loop
I[8] timeit np.ptp(a)
10000 loops, best of 3: 103 us per loop


More information about the NumPy-Discussion mailing list