[Numpy-discussion] NumPy-Discussion Digest, Vol 84, Issue 19

Graeme B. Bell grb at skogoglandskap.no
Mon Sep 9 03:40:56 EDT 2013


Hi again Julian,

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

Not really. The 4 unique alternative implementations provided all work quickly and correctly as-is, without a need to jump through a strange idiomatic hoop, so the problem does indeed lie with the implementation approach used in the current numpy.any(). 

It is unreasonable to expect users to know and always prepare their data using the idiom you propose if they might want to use the .any() function. If quirky idioms are needed to fix the performance of .any(), they should be placed in the implementation of .any().


>  this has the same performance as your code:
> a = empty([3] list(A.shape)

How do you know? This isn't valid Python, it won't run. Please can you send me a working version I can benchmark and compare? 

Graeme. 



On Sep 5, 2013, at 8:52 PM, <numpy-discussion-request at scipy.org>
 wrote:

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




More information about the NumPy-Discussion mailing list