[Numpy-discussion] use ufunc for arbitrary positional arguments?

Sebastian Berg sebastian at sipsolutions.net
Fri Oct 10 15:36:50 EDT 2014


On Fr, 2014-10-10 at 14:30 -0400, Benjamin Root wrote:
> Oy! I got to be having a brain fart today. np.all on the list of
> boolean arrays applied on the first(?) axis is much clearer than any
> ufunc or reduce call. And to answer the next question... use np.any
> for logical_or()...
> 

Of course np.all is pretty much identical to np.logical_and.reduce(),
and that is defined for all ufuncs. Of course your list of arrays will
be converted to one large array first, so the python reduce may actually
be faster in many cases.

- Sebastian

> 
> Thanks!
> 
> Ben Root
> 
> 
> On Fri, Oct 10, 2014 at 2:27 PM, Stephan Hoyer <shoyer at gmail.com>
> wrote:
>         On Fri, Oct 10, 2014 at 11:23 AM, Benjamin Root
>         <ben.root at ou.edu> wrote:
>                 I have a need to "and" together an arbitrary number of
>                 boolean arrays. np.logical_and() expects only two
>                 positional arguments. There has got to be some sort of
>                 easy way to just and these together using the ufunc
>                 mechanism, right?
>                 
>         
>         
>         Do you really need a ufunc? The obvious way to do this (at
>         least to me) would be use reduce (if you're especially
>         concerned about memory) or just np.all.
>         
>         
>         
>         
>         _______________________________________________
>         NumPy-Discussion mailing list
>         NumPy-Discussion at scipy.org
>         http://mail.scipy.org/mailman/listinfo/numpy-discussion
>         
> 
> 
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20141010/e7d1ba96/attachment.sig>


More information about the NumPy-Discussion mailing list