[Numpy-discussion] all elements equal

Benjamin Root ben.root@ou....
Mon Mar 5 13:52:04 CST 2012


On Mon, Mar 5, 2012 at 1:44 PM, Keith Goodman <kwgoodman@gmail.com> wrote:

> 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
>

Another issue to watch out for is if the array is empty.  Technically
speaking, that should be True, but some of the solutions offered so far
would fail in this case.

Ben Root
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20120305/a5ec606d/attachment.html 


More information about the NumPy-Discussion mailing list