Re: [Numpy-discussion] uint64 typecasting with scalars broken (?)

2007-04-23 Thread Christian Marquardt
On Mon, April 23, 2007 01:28, Charles R Harris wrote: > Looks like a bug to me: > > In [5]: x = array([1],dtype=uint64) > > In [6]: type(x[0]) > Out[6]: > > In [7]: type(x[0]+1) > Out[7]: > > Chuck Yeah. Especially as it works apparently fine for uint32 and int64. Christian. __

[Numpy-discussion] efficient use of numpy.where() and .any()

2007-04-23 Thread Mark.Miller
Greetings: In some of my code, I need to use large matrix of random numbers that meet specific criteria (i.e., some random numbers need to be removed and replaces with new ones). I have been working with .any() and .where() to facilitate this process. In the code below, .any() is used in a w

[Numpy-discussion] Fwd: Getting subarray

2007-04-23 Thread Tommy Grav
I have two arrays: a = numpy.array([0,1,2,3,4,5,6,7,8,9]) b = numpy.array([0,0,1,1,2,2,0,1,2,3]) I would like to get the part of a that corresponds to where b is equal to i. For example: i = 0 => ([0,1,6]) i = 1 => ([2,3,7]) Cheers Tommy ___ Num

Re: [Numpy-discussion] Fwd: Getting subarray

2007-04-23 Thread Steve Lianoglou
Hi, On Apr 23, 2007, at 11:30 AM, Tommy Grav wrote: > I have two arrays: > > a = numpy.array([0,1,2,3,4,5,6,7,8,9]) > b = numpy.array([0,0,1,1,2,2,0,1,2,3]) > > I would like to get the part of a that corresponds > to where b is equal to i. > > For example: > > i = 0 => ([0,1,6]) > i = 1 => ([2,3,

Re: [Numpy-discussion] efficient use of numpy.where() and .any()

2007-04-23 Thread Pierre GM
On Monday 23 April 2007 10:37:57 Mark.Miller wrote: > Greetings: > > In some of my code, I need to use large matrix of random numbers that > meet specific criteria (i.e., some random numbers need to be removed and > replaces with new ones). > > I have been working with .any() and .where() to facili

Re: [Numpy-discussion] Fwd: Getting subarray

2007-04-23 Thread Gael Varoquaux
On Mon, Apr 23, 2007 at 11:44:08AM -0400, Steve Lianoglou wrote: > > I have two arrays: > > a = numpy.array([0,1,2,3,4,5,6,7,8,9]) > > b = numpy.array([0,0,1,1,2,2,0,1,2,3]) > > I would like to get the part of a that corresponds > > to where b is equal to i. > > For example: > > i = 0 => ([0,1,

Re: [Numpy-discussion] Fwd: Getting subarray

2007-04-23 Thread Steve Lianoglou
> I have two arrays: > > a = numpy.array([0,1,2,3,4,5,6,7,8,9]) > b = numpy.array([0,0,1,1,2,2,0,1,2,3]) > > I would like to get the part of a that corresponds > to where b is equal to i. > > For example: > > i = 0 => ([0,1,6]) > i = 1 => ([2,3,7]) a[b == 1] and a[b == 0] work too, btw. -ste

Re: [Numpy-discussion] efficient use of numpy.where() and .any()

2007-04-23 Thread Pierre GM
Oh, I pressed "send" too early. Just an addition: numpy.where creates a new array from some condition. If you only want to change elements of an existing array that satisfies a given condition, indexing is far more efficient: no temporary is created. Hence the suggestion of a[a<0] _

Re: [Numpy-discussion] efficient use of numpy.where() and .any()

2007-04-23 Thread Mark.Miller
Excellent suggestions...just a few comments: Pierre GM wrote: > On Monday 23 April 2007 10:37:57 Mark.Miller wrote: >> Greetings: >> >> In some of my code, I need to use large matrix of random numbers that >> meet specific criteria (i.e., some random numbers need to be removed and >> replaces with

Re: [Numpy-discussion] efficient use of numpy.where() and .any()

2007-04-23 Thread Robert Kern
Mark.Miller wrote: > Pierre GM wrote: >> a[a<0] = numpy.random.normal(0,1) > > This is a neat construct that I didn't realize was possible. However, > it has the undesirable (in my case) effect of placing a single new > random number in each locations where a<0. While this could work, I > id

Re: [Numpy-discussion] efficient use of numpy.where() and .any()

2007-04-23 Thread Anne Archibald
On 23/04/07, Pierre GM <[EMAIL PROTECTED]> wrote: > Have you tried nonzero() ? > > a[a<0] = numpy.random.normal(0,1) > > will put a random number from the normal distribution where your initial a is > negative. No Python loops needed, no Python temps. When you say "no python temps" I guess you me

Re: [Numpy-discussion] efficient use of numpy.where() and .any()

2007-04-23 Thread Pierre GM
> > Have you tried nonzero() ? > > Nonzero isn't quite what I'm after, as the tests are more complicated > than what I illustrated in my example. Tests such as (a<0)&(b>1) will give you arrays of booleans. The nonzero give you where the two conditions are met (viz, where the results is True, or 1

Re: [Numpy-discussion] efficient use of numpy.where() and .any()

2007-04-23 Thread Pierre GM
> When you say "no python temps" I guess you mean, no temporary > *variables*? If I understand correctly, this allocates a temporary > boolean array to hold the result of "a<0". Indeed, hence my precising "no *python* temps". There still be a tmp created at one point or another (if I'm not mista

Re: [Numpy-discussion] efficient use of numpy.where() and .any()

2007-04-23 Thread Mark.Miller
Robert Kern wrote: > Certainly. How about this? > > mask = (a<0) > a[mask] = numpy.random.normal(0, 1, size=mask.sum()) > That's slick. I believe it's precisely what I'm after. Appreciate it, -Mark ___ Numpy-discussion mailing list Numpy-discussion

Re: [Numpy-discussion] efficient use of numpy.where() and .any()

2007-04-23 Thread Anne Archibald
On 23/04/07, Pierre GM <[EMAIL PROTECTED]> wrote: > Note that in addition of the bitwise operators, you can use the "logical_" > functions. OK, you'll still end up w/ temporaries, but I wonder whether there > couldn't be some tricks to bypass that... If you're really determined not to make many t

[Numpy-discussion] Inplace reshape

2007-04-23 Thread Gael Varoquaux
Hi, I thought I remembered there was a way to reshape in-place an array, but neither google, nor greping my mailbox brings anything out. Am I wrong, or is there indeed a way to reshape in-place an array ? Cheers, Gaƫl ___ Numpy-discussion mailing list

Re: [Numpy-discussion] Inplace reshape

2007-04-23 Thread Anne Archibald
On 23/04/07, Gael Varoquaux <[EMAIL PROTECTED]> wrote: > Hi, > > I thought I remembered there was a way to reshape in-place an array, but > neither google, nor greping my mailbox brings anything out. > Am I wrong, or is there indeed a way to reshape in-place an array ? Sometimes it's just impossib

Re: [Numpy-discussion] Inplace reshape

2007-04-23 Thread Timothy Hochberg
On 4/23/07, Gael Varoquaux <[EMAIL PROTECTED]> wrote: Hi, I thought I remembered there was a way to reshape in-place an array, but neither google, nor greping my mailbox brings anything out. Am I wrong, or is there indeed a way to reshape in-place an array ? Just set the shape of the array:

Re: [Numpy-discussion] Inplace reshape

2007-04-23 Thread Robert Kern
Gael Varoquaux wrote: > Hi, > > I thought I remembered there was a way to reshape in-place an array, but > neither google, nor greping my mailbox brings anything out. > Am I wrong, or is there indeed a way to reshape in-place an array ? .reshape() -- Robert Kern "I have come to believe that th

Re: [Numpy-discussion] Inplace reshape

2007-04-23 Thread Gael Varoquaux
On Mon, Apr 23, 2007 at 10:20:43AM -0700, Timothy Hochberg wrote: >Just set the shape of the array: >somearray.shape = newshape Of course ! Thanks On Mon, Apr 23, 2007 at 12:20:51PM -0500, Robert Kern wrote: > .reshape() Unless I miss something obvious "a.reshape()" doesn't modify a

Re: [Numpy-discussion] Inplace reshape

2007-04-23 Thread Robert Kern
Gael Varoquaux wrote: > On Mon, Apr 23, 2007 at 12:20:51PM -0500, Robert Kern wrote: >> .reshape() > > Unless I miss something obvious "a.reshape()" doesn't modify a, which is > somewhat missleading, IMHO. Nope, you caught me in a moment of stupidity. -- Robert Kern "I have come to believe tha

Re: [Numpy-discussion] Inplace reshape

2007-04-23 Thread Christopher Barker
Gael Varoquaux wrote: > Unless I miss something obvious "a.reshape()" doesn't modify a, which is > somewhat missleading, IMHO. quite correct. .reshape() creates a new array that shared data with the original: >>> import numpy >>> a = numpy.zeros((2,3)) >>> help(a.reshape) Help on built-in fu

Re: [Numpy-discussion] Inplace reshape

2007-04-23 Thread Pierre GM
On Monday 23 April 2007 13:36:26 Christopher Barker wrote: > Gael Varoquaux wrote: > > Unless I miss something obvious "a.reshape()" doesn't modify a, which is > > somewhat missleading, IMHO. > > quite correct. .reshape() creates a new array that shared data with the > original: Mmh. My understand

Re: [Numpy-discussion] Inplace reshape

2007-04-23 Thread Charles R Harris
On 4/23/07, Christopher Barker <[EMAIL PROTECTED]> wrote: Gael Varoquaux wrote: > Unless I miss something obvious "a.reshape()" doesn't modify a, which is > somewhat missleading, IMHO. quite correct. .reshape() creates a new array that shared data with the original: Sometimes it do, sometime

Re: [Numpy-discussion] Inplace reshape

2007-04-23 Thread Keith Goodman
On 4/23/07, Christopher Barker <[EMAIL PROTECTED]> wrote: > reshape(...) > a.reshape(d1, d2, ..., dn, order='c') > > Return a new array from this one. The new array must have the same > > number of elements as self. Also always returns a view or raises a > ValueError if that i

Re: [Numpy-discussion] efficient use of numpy.where() and .any()

2007-04-23 Thread Francesc Altet
El dl 23 de 04 del 2007 a les 12:47 -0400, en/na Anne Archibald va escriure: > On 23/04/07, Pierre GM <[EMAIL PROTECTED]> wrote: > > > Note that in addition of the bitwise operators, you can use the "logical_" > > functions. OK, you'll still end up w/ temporaries, but I wonder whether > > there >

Re: [Numpy-discussion] Inplace reshape

2007-04-23 Thread Charles R Harris
On 4/23/07, Keith Goodman <[EMAIL PROTECTED]> wrote: On 4/23/07, Christopher Barker <[EMAIL PROTECTED]> wrote: > reshape(...) > a.reshape(d1, d2, ..., dn, order='c') > > Return a new array from this one. The new array must have the same > > number of elements as self. Also alway

Re: [Numpy-discussion] Inplace reshape

2007-04-23 Thread Christopher Barker
Charles R Harris wrote: > Here's a better doc string that explains "This will be a new view > object if possible; otherwise, it will return a copy." Does this exist somewhere, or are you contributing it now? > I think that it should raise an error, or warn, if it needs to make a > copy,

Re: [Numpy-discussion] Inplace reshape

2007-04-23 Thread Keith Goodman
On 4/23/07, Christopher Barker <[EMAIL PROTECTED]> wrote: > Charles R Harris wrote: > > Here's a better doc string that explains "This will be a new view > > object if possible; otherwise, it will return a copy." > > Does this exist somewhere, or are you contributing it now? At the moment

[Numpy-discussion] Oddity with numpy.int64 integer division

2007-04-23 Thread Christian Marquardt
Dear all, this is odd: >>> import numpy as np >>> fact = 2825L * 86400L >>> nn = np.array([-20905000L]) >>> nn array([-20905000], dtype=int64) >>> nn[0] // fact 0 But: >>> long(nn[0]) // fact -1L Is this a bug in numpy, or in python's implementation of longs? I w

Re: [Numpy-discussion] Oddity with numpy.int64 integer division

2007-04-23 Thread Christian Marquardt
Actually, it happens for normal integers as well: >>> n = np.array([-5, -100, -150]) >>> n // 100 array([ 0, -1, -1]) >>> -5//100, -100//100, -150//100 (-1, -1, -2) On Mon, April 23, 2007 22:20, Christian Marquardt wrote: > Dear all, > > this is odd: > >>>> import numpy as np

Re: [Numpy-discussion] Oddity with numpy.int64 integer division

2007-04-23 Thread Christian Marquardt
Hmmm, On Mon, April 23, 2007 22:29, Christian Marquardt wrote: > Actually, > > it happens for normal integers as well: > >>>> n = np.array([-5, -100, -150]) >>>> n // 100 >array([ 0, -1, -1]) >>>> -5//100, -100//100, -150//100 >(-1, -1, -2) and finally: >>> n % 100 arra

Re: [Numpy-discussion] Inplace reshape

2007-04-23 Thread Christopher Barker
Keith Goodman wrote: > At the moment numpy.reshape and array.reshape have different doc > strings (I'm using numpy 1.0.2.dev3546). The one I pasted is from > numpy.reshape. And I see from there: :See also: numpy.ndarray.reshape() is the equivalent method. so it looks like they are th

Re: [Numpy-discussion] Inplace reshape

2007-04-23 Thread Robert Kern
Christopher Barker wrote: > if numpy.reshape() is delegating to ndarray.reshape() couldn't they > share docstrings somehow? Yes, of course. I got bored halfway through the conversions and didn't get to doing the methods. If you want to speed up the process, please submit a patch. -- Robert Ker

Re: [Numpy-discussion] Oddity with numpy.int64 integer division

2007-04-23 Thread David M. Cooke
On Apr 23, 2007, at 16:41 , Christian Marquardt wrote: On Mon, April 23, 2007 22:29, Christian Marquardt wrote: Actually, it happens for normal integers as well: n = np.array([-5, -100, -150]) n // 100 array([ 0, -1, -1]) -5//100, -100//100, -150//100 (-1, -1, -2) and finally: n

Re: [Numpy-discussion] uint64 typecasting with scalars broken (?)

2007-04-23 Thread Travis Oliphant
Christian Marquardt wrote: > Hello, > > The following is what I expected... > >>>> y = 1234 >>>> x = array([1], dtype = "uint64") >>>> print x + y, (x + y).dtype.type >[1235] > > This is "what you expect" only because y is a scalar and cannot determine the "kind" of the output

Re: [Numpy-discussion] Oddity with numpy.int64 integer division

2007-04-23 Thread Warren Focke
But even C89 required that x == (x/y)*y + (x%y), and that's not the case here. w On Mon, 23 Apr 2007, David M. Cooke wrote: > On Apr 23, 2007, at 16:41 , Christian Marquardt wrote: > > On Mon, April 23, 2007 22:29, Christian Marquardt wrote: > >> Actually, > >> > >> it happens for normal integer

Re: [Numpy-discussion] uint64 typecasting with scalars broken (?)

2007-04-23 Thread Charles R Harris
On 4/23/07, Travis Oliphant <[EMAIL PROTECTED]> wrote: Christian Marquardt wrote: > Hello, > > The following is what I expected... > >>>> y = 1234 >>>> x = array([1], dtype = "uint64") >>>> print x + y, (x + y).dtype.type >[1235] > > This is "what you expect" only because y is

Re: [Numpy-discussion] uint64 typecasting with scalars broken (?)

2007-04-23 Thread Charles R Harris
On 4/23/07, Charles R Harris <[EMAIL PROTECTED]> wrote: On 4/23/07, Travis Oliphant <[EMAIL PROTECTED]> wrote: > > Christian Marquardt wrote: > > Hello, > > > > The following is what I expected... > > > >>>> y = 1234 > >>>> x = array([1], dtype = "uint64") > >>>> print x + y, (x +