[Numpy-discussion] varargs for logical_or, etc

Benjamin Root ben.root@ou....
Tue Jun 5 11:59:10 CDT 2012


On Tue, Jun 5, 2012 at 10:37 AM, Robert Kern <robert.kern@gmail.com> wrote:

> On Tue, Jun 5, 2012 at 2:54 PM, Neal Becker <ndbecker2@gmail.com> wrote:
> > I think it's unfortunate that functions like logical_or are limited to
> binary.
> >
> > As a workaround, I've been using this:
> >
> > def apply_binary (func, *args):
> >    if len (args) == 1:
> >        return args[0]
> >    elif len (args) == 2:
> >        return func (*args)
> >    else:
> >        return func (
> >            apply_binary (func, *args[:len(args)/2]),
> >            apply_binary (func, *args[(len(args))/2:]))
> >
> > Then for example:
> >
> > punc2 = np.logical_and (u % 5 == 4,
> >                       apply_binary (np.logical_or, u/5 == 3, u/5 == 8,
> u/5 ==
> > 13))
>
>
> reduce(np.logical_and, args)
>
>
I would love it if we could add something like that to the doc-string of
those functions because I don't think it is immediately obvious.  How do we
do that for ufuncs?

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


More information about the NumPy-Discussion mailing list