[Numpy-discussion] fast_any_all , a trivial but fast/useful helper function for numpy

Julian Taylor jtaylor.debian at googlemail.com
Thu Sep 5 14:53:38 EDT 2013


hi,
its not np.any that is slow in this case its np.array([A, B, C])

np.dstack([A, B, C]) is better but writing it like this has the same
performance as your code:
a = empty([3] list(A.shape)
a[0] = A>5; a[1] = B<2; a[2] = A>10;
np.any(a, 0)

I'll check if creating an array from a sequence can be improved for this
case.

On 05.09.2013 10:54, Graeme B. Bell wrote:
> 
> 
> Hi Julian,
> 
> Thanks for the post.  It's great to hear that the main numpy function is improving in 1.8, though I think there is still plenty of value here for performance junkies :-)   
> 
> I don't have 1.8beta installed (and I can't conveniently install it on my machines just now). If you have time, and have the beta installed, could you try this and mail me the output from the benchmark?  I'm curious to know. 
> 
> # git clone https://github.com/gbb/numpy-fast-any-all.git
> # cd numpy-fast-any-all
> # python test-fast-any-all.py
> 
> Graeme
> 
> 
> On Sep 4, 2013, at 7:38 PM, Julian Taylor <jtaylor.debian at googlemail.com> wrote:
> 
>>>
>>> The result is 14 to 17x faster than np.any() for this use case.*
>>
>> any/all and boolean operations have been significantly speed up by
>> vectorization in numpy 1.8 [0].
>> They are now around 10 times faster than before, especially if the
>> boolean array fits into one of the cpu caching layers.
> 




More information about the NumPy-Discussion mailing list