[Numpy-discussion] varargs for logical_or, etc

Ralf Gommers ralf.gommers@googlemail....
Tue Jun 5 13:51:26 CDT 2012


On Tue, Jun 5, 2012 at 6:59 PM, Benjamin Root <ben.root@ou.edu> wrote:

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

Edit numpy/core/code_generators/ufunc_docstrings.py

Ralf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20120605/3f0a7db5/attachment.html 


More information about the NumPy-Discussion mailing list