[Numpy-discussion] Numpy where
Charles R Harris
charlesr.harris at gmail.com
Fri Mar 13 21:07:17 EDT 2015
On Fri, Mar 13, 2015 at 2:09 PM, Charles R Harris <charlesr.harris at gmail.com
> wrote:
>
>
> On Fri, Mar 13, 2015 at 1:26 PM, Nathaniel Smith <njs at pobox.com> wrote:
>
>> On Thu, Mar 12, 2015 at 9:35 PM, Benjamin Root <ben.root at ou.edu> wrote:
>> > I think the question is if scalars should be acceptable for the first
>> > argument, not if it should be for the 2nd and 3rd argument.
>> >
>> > If scalar can be given for the first argument, the the first three makes
>> > sense. Although, I have no clue why we would allow that.
>>
>> Why wouldn't we? The where function takes three arguments which are
>> broadcast against each other, so disallowing scalars would require
>> adding a special case.
>>
>
> I'm coming to the conclusion that only #4 is incorrect. The process seems
> to go: cast scalars to 1-D arrays (hence #1 and #3), and indexing results
> in #2.
>
> The oddity is that the second and third arguments are optional, and the
> action of the function depends on that. I would have made those arguments
> required as omitting them gives the same as a call to nonzero. But things
> are as they are...
>
To summarize, np.where is OK as is, np.ma.where needs fixing.
As for deprecating the use of np.where as np.nonzero, that looks very easy
to do in the code. However, the PyArray_Where function is in the numpy
C-API so we might want to be careful about doing that.
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20150313/838b7d47/attachment.html>
More information about the NumPy-Discussion
mailing list