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,7])

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 facilitate

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. -steve

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 new

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

2007-04-23 Thread Robert Kern
Mark.Miller wrote: Pierre GM wrote: a[a0] = 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 a0. While this could work, I ideally

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 (a0)(b1) 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 a0. Indeed, hence my precising no *python* temps. There still be a tmp created at one point or another (if I'm not mistaken)

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

2007-04-23 Thread Mark.Miller
Robert Kern wrote: Certainly. How about this? mask = (a0) 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

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 temps,

[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 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 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 that the

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 understanding is

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 couldn't

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 would think both

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 fact =

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 array([95, 0, 50])

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 the

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] type 'numpy.uint64' 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 integers as well:

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] type 'numpy.uint64' This is what you expect only because y is a

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 + y).dtype.type [1235] type