Re: [Numpy-discussion] numpy where and dtype in 1.9

2015-07-30 Thread Nathan Jensen
Thanks for the link. I'm glad I'm not the only one tripping over the where() changes. Should I open a new ticket for what I've encountered, or just add a comment to 5095 that the behavior of the output's dtype is also different? It doesn't sound like it's going to be fixed in 1.9, so I'm not sur

Re: [Numpy-discussion] numpy where and dtype in 1.9

2015-07-29 Thread Benjamin Root
What a coincidence! A very related bug just got re-opened today at my behest: https://github.com/numpy/numpy/issues/5095 Not the same, but I wouldn't be surprised if it stems from the same sources. The short of it... np.where(x, 0, x) where x is a masked array, will return a masked array in 1.8.

[Numpy-discussion] numpy where and dtype in 1.9

2015-07-29 Thread Nathan Jensen
Hi, The numpy.where() function was rewritten in numpy 1.9 to speed it up. I traced it to this changeset. https://github.com/numpy/numpy/commit/593e3c30c24f0c61a271dc883c614724d7a57e1e The weird thing is the 1.9 behavior changed the resulting dtype in some situations when using scalar values as t

Re: [Numpy-discussion] Numpy where

2015-03-13 Thread Charles R Harris
On Fri, Mar 13, 2015 at 2:09 PM, Charles R Harris wrote: > > > On Fri, Mar 13, 2015 at 1:26 PM, Nathaniel Smith wrote: > >> On Thu, Mar 12, 2015 at 9:35 PM, Benjamin Root wrote: >> > I think the question is if scalars should be acceptable for the first >> > argument, not if it should be for the

Re: [Numpy-discussion] Numpy where

2015-03-13 Thread Charles R Harris
On Fri, Mar 13, 2015 at 1:26 PM, Nathaniel Smith wrote: > On Thu, Mar 12, 2015 at 9:35 PM, Benjamin Root 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 a

Re: [Numpy-discussion] Numpy where

2015-03-13 Thread Nathaniel Smith
On Thu, Mar 12, 2015 at 5:02 PM, Charles R Harris wrote: > Hi All, > > This is apropos gh-5582 dealing with some corner cases of np.where. The > following are the current behavior > import numpy numpy.where(True) # case 1 > ... (array([0]),) numpy.where(True, None, None) # case 2

Re: [Numpy-discussion] Numpy where

2015-03-13 Thread Nathaniel Smith
On Thu, Mar 12, 2015 at 9:35 PM, Benjamin Root 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

Re: [Numpy-discussion] Numpy where

2015-03-13 Thread John Kirkham
Hey Everyone, I felt like I should add to the mix. I added the issue ( https://github.com/numpy/numpy/issues/5679 ) to tie these options together. My main concern is that both wheres behave the same. As far as using a scalar as the first argument, it was an easy example. We could have used actu

Re: [Numpy-discussion] Numpy where

2015-03-12 Thread Benjamin Root
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. Ben Root On Mar 12, 2015 9:25 PM, "Na

Re: [Numpy-discussion] Numpy where

2015-03-12 Thread Nathaniel Smith
On Mar 12, 2015 5:02 PM, "Charles R Harris" wrote: > > Hi All, > > This is apropos gh-5582 dealing with some corner cases of np.where. The following are the current behavior > > >>> import numpy > >>> numpy.where(True) # case 1 > ... (array([0]),) > >>> numpy.where(True, None, None) # case 2 > .

[Numpy-discussion] Numpy where

2015-03-12 Thread Charles R Harris
Hi All, This is apropos gh-5582 dealing with some corner cases of np.where. The following are the current behavior >>> import numpy >>> numpy.where(True) # case 1 ... (array([0]),) >>> numpy.where(True, None, None) # case 2 ... array(None, dtype=object

Re: [Numpy-discussion] numpy where function on different sized arrays

2012-11-25 Thread Siegfried Gonzi
On 25 Nov 2012, at 00:29, numpy-discussion-requ...@scipy.org wrote: > > Message: 3 > Date: Sat, 24 Nov 2012 23:23:36 +0100 > From: Da?id > Subject: Re: [Numpy-discussion] numpy where function on different > sized arrays > To: Discussion of Numerical

Re: [Numpy-discussion] numpy where function on different sized arrays

2012-11-24 Thread David Warde-Farley
On Sat, Nov 24, 2012 at 7:08 PM, David Warde-Farley < d.warde.far...@gmail.com> wrote: > I think that would lose information as to which value in B was at each > position. I think you want: > > (premature send, stupid Gmail...) idx = {} for i, x in enumerate(a): for j, y in enumerate(x):

Re: [Numpy-discussion] numpy where function on different sized arrays

2012-11-24 Thread David Warde-Farley
I think that would lose information as to which value in B was at each position. I think you want: On Sat, Nov 24, 2012 at 5:23 PM, Daπid wrote: > A pure Python approach could be: > > for i, x in enumerate(a): > for j, y in enumerate(x): > if y in b: >

Re: [Numpy-discussion] numpy where function on different sized arrays

2012-11-24 Thread Daπid
A pure Python approach could be: for i, x in enumerate(a): for j, y in enumerate(x): if y in b: idx.append((i,j)) Of course, it is slow if the arrays are large, but it is very readable, and probably very fast if cythonised. David. On Sat, Nov 24,

Re: [Numpy-discussion] numpy where function on different sized arrays

2012-11-24 Thread David Warde-Farley
M = A[..., np.newaxis] == B will give you a 40x60x20 boolean 3d-array where M[..., i] gives you a boolean mask for all the occurrences of B[i] in A. If you wanted all the (i, j) pairs for each value in B, you could do something like import numpy as np from itertools import izip, groupby from ope

Re: [Numpy-discussion] numpy where function on different size

2012-11-24 Thread Siegfried Gonzi
> Message: 6 > Date: Sat, 24 Nov 2012 20:36:45 + > From: Siegfried Gonzi > Subject: [Numpy-discussion] numpy where function on different size > Hi all >This must have been answered in the past but my google search > capabilities are not the best. >Given an array A sa

[Numpy-discussion] numpy where function on different sized arrays

2012-11-24 Thread Siegfried Gonzi
Hi all This must have been answered in the past but my google search capabilities are not the best. Given an array A say of dimension 40x60 and given another array/vector B of dimension 20 (the values in B occur only once). What I would like to do is the following which of course does not w