
Hi. Two things. 1) The doc-string of numpy.where() states that transpose(where(cond, x,y)) whould always return a 2d-array. How can this be true?? It also says (before) that if x,y are given where(cond,x,y) always returns an array of the same shape as cond .... 2) Could we have another optional argument "dtype" in numpy.where()? Otherwise I would have to always write code like this: a = N.where( arr>x, 1.0, 0.0) a = a.astype(N.float32) I use N.__version__ == '1.0.1' Thanks, Sebastian Haase

Sebastian Haase wrote:
Hi. Two things. 1) The doc-string of numpy.where() states that transpose(where(cond, x,y)) whould always return a 2d-array. How can this be true?? It also says (before) that if x,y are given where(cond,x,y) always returns an array of the same shape as cond ....
It is wrong. It actually meant transpose(where(condition))
2) Could we have another optional argument "dtype" in numpy.where()? Otherwise I would have to always write code like this: a = N.where( arr>x, 1.0, 0.0) a = a.astype(N.float32)
a = N.where(arr > x, N.float32(1), N.float32(0)) -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco

On 7/14/07, Robert Kern <robert.kern@gmail.com> wrote:
Sebastian Haase wrote:
Hi. Two things. 1) The doc-string of numpy.where() states that transpose(where(cond, x,y)) whould always return a 2d-array. How can this be true?? It also says (before) that if x,y are given where(cond,x,y) always returns an array of the same shape as cond ....
It is wrong. It actually meant
transpose(where(condition))
2) Could we have another optional argument "dtype" in numpy.where()? Otherwise I would have to always write code like this: a = N.where( arr>x, 1.0, 0.0) a = a.astype(N.float32)
a = N.where(arr > x, N.float32(1), N.float32(0))
If the x,y arguments are not scalars but (large) arrays this would need lots of unneccessary temporary memory (peak of 3 times the needed output memory size). I would wish that this function, and others which generate output arrays, all get an addition optional dtype argument. (Just like the functions in nd-image) Comments? Thanks for your quick reply, Robert, as always. -Sebastian

Sebastian Haase wrote:
On 7/14/07, Robert Kern <robert.kern@gmail.com> wrote:
Sebastian Haase wrote:
2) Could we have another optional argument "dtype" in numpy.where()? Otherwise I would have to always write code like this: a = N.where( arr>x, 1.0, 0.0) a = a.astype(N.float32) a = N.where(arr > x, N.float32(1), N.float32(0))
If the x,y arguments are not scalars but (large) arrays this would need lots of unneccessary temporary memory (peak of 3 times the needed output memory size). I would wish that this function, and others which generate output arrays, all get an addition optional dtype argument. (Just like the functions in nd-image)
Comments?
I look forward to your patch. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco

On 7/15/07, Robert Kern <robert.kern@gmail.com> wrote:
Sebastian Haase wrote:
On 7/14/07, Robert Kern <robert.kern@gmail.com> wrote:
Sebastian Haase wrote:
2) Could we have another optional argument "dtype" in numpy.where()? Otherwise I would have to always write code like this: a = N.where( arr>x, 1.0, 0.0) a = a.astype(N.float32) a = N.where(arr > x, N.float32(1), N.float32(0))
If the x,y arguments are not scalars but (large) arrays this would need lots of unneccessary temporary memory (peak of 3 times the needed output memory size). I would wish that this function, and others which generate output arrays, all get an addition optional dtype argument. (Just like the functions in nd-image)
Comments?
I look forward to your patch.
Which file(s) should I be looking for?

On 7/15/07, Robert Kern <robert.kern@gmail.com> wrote:
Sebastian Haase wrote:
On 7/14/07, Robert Kern <robert.kern@gmail.com> wrote:
Sebastian Haase wrote:
2) Could we have another optional argument "dtype" in numpy.where()? Otherwise I would have to always write code like this: a = N.where( arr>x, 1.0, 0.0) a = a.astype(N.float32) a = N.where(arr > x, N.float32(1), N.float32(0))
If the x,y arguments are not scalars but (large) arrays this would need lots of unneccessary temporary memory (peak of 3 times the needed output memory size). I would wish that this function, and others which generate output arrays, all get an addition optional dtype argument. (Just like the functions in nd-image)
Comments?
I look forward to your patch.
Which file(s) should I be looking for?

Sebastian Haase wrote:
Which file(s) should I be looking for?
numpy/core/src/multiarraymodule.c . You will need to modify the functions array_where() and PyArray_Where(). Be sure to update ma.py to match, and update numarray/functions.py to make use of the out= argument (numarray had it and we just fake it). -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
participants (3)
-
Robert Kern
-
Sebastian Haase
-
Sebastian Haase