[Numpy-discussion] Adding 'where' to ufunc methods?

Nathaniel Smith njs at pobox.com
Wed Apr 1 16:02:52 EDT 2015


On Apr 1, 2015 12:55 PM, <josef.pktd at gmail.com> wrote:
>
> On Wed, Apr 1, 2015 at 3:47 PM, Nathaniel Smith <njs at pobox.com> wrote:
> > On Wed, Apr 1, 2015 at 11:34 AM, Jaime Fernández del Río
> > <jaime.frio at gmail.com> wrote:
> >> This question on StackOverflow:
> >>
> >>
http://stackoverflow.com/questions/29394377/minimum-of-numpy-array-ignoring-diagonal
> >>
> >> Got me thinking that I had finally found a use for the 'where' kwarg of
> >> ufuncs. Unfortunately it is only provided for the ufunc itself, but
not for
> >> any of its methods.
> >>
> >> Is there any fundamental reason these were not implemented back in the
day?
> >> Any frontal opposition to having them now?
> >
> > The where= argument stuff was rescued from the last aborted attempt to
> > add missing value support to numpy. The only reason they aren't
> > implemented for the ufunc methods is that Mark didn't get that far.
> >
> > +1 to adding them now.
>
> can you get `where` in ufuncs without missing value support?

where= is implemented since 1.7 iirc, for regular ufunc calls. I.e. you can
currently do np.add(a, b, where=mask), but not np.add.reduce(a, b,
where=mask).

> what's the result for ufuncs that are not reduce operations?

The operation skips over any entries where the mask is false. So if you
pass an out= array, the masked out entries will remain unchanged from
before the call; if you don't pass an out= array then one will be allocated
for you as if by calling np.empty, and then the masked out entries will
remain uninitialized.

> what's the result for reduce operations along an axis if there is
> nothing there (in a row or column or ...)?

The same as a reduce operation on a zero length axis: the identity if the
ufunc has one, and an error otherwise.

-n
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20150401/924e2db9/attachment.html>


More information about the NumPy-Discussion mailing list