[Numpy-discussion] summarizing blocks of an array using a moving window

2010-07-21 Thread Robin Kraft
Hello all, The short version: For a given NxN array, is there an efficient way to use a moving window to collect a summary statistic on a chunk of the array, and insert it into another array? The long version: I am trying to resample an image loaded with GDAL into an NxN array. Note that this

Re: [Numpy-discussion] lstsq functionality

2010-07-21 Thread Keith Goodman
On Wed, Jul 21, 2010 at 8:24 PM, Charles R Harris wrote: > > On Wed, Jul 21, 2010 at 5:44 PM, Keith Goodman wrote: >> Can someone confirm that the copy in np.linalg.lstsq >> >> bstar[:b.shape[0],:n_rhs] = b.copy() >> >> is not needed? I'm assuming that ndarray.__setitem__ never gives a >> view o

Re: [Numpy-discussion] lstsq functionality

2010-07-21 Thread Charles R Harris
On Wed, Jul 21, 2010 at 5:44 PM, Keith Goodman wrote: > On Wed, Jul 21, 2010 at 4:35 PM, Skipper Seabold > wrote: > > On Tue, Jul 20, 2010 at 10:24 PM, Keith Goodman > wrote: > >> Good point. Looks like we can get rid of 2 copies! I didn't get rid of > >> the second copy but I did cut things do

Re: [Numpy-discussion] UMFPACK interface is unexpectedly slow

2010-07-21 Thread Ioan-Alexandru Lazar
I hope I won't get identified as a spam bot :-). While I have not resolved the problem itself, this is an issue that I cannot reproduce on our cluster. I wanted to get back with some actual timings from the real hardware we are going to be using and some details about the matrices, so as not to cha

[Numpy-discussion] UMFPACK interface is unexpectedly slow

2010-07-21 Thread Ioan-Alexandru Lazar
Hello everyone, First of all, let me apologize for my earlier message; I made the mistake of trying to indent my code using SquirrelMail's horrible interface -- and pressing Tab and Space resulted in sending my (incomplete) e-mail to the list. Cursed be Opera's keyboard shortcuts now :-). I'm cur

[Numpy-discussion] (no subject)

2010-07-21 Thread Ioan-Alexandru Lazar
Hello everyone, I'm currently planning to use a Python-based infrastructure for our HPC project. I've previously used NumPy and SciPy for basic scientific computing tasks, but performance hasn't been quite an issue for me until now. At the moment I'm not too sure as to what to do next though, and

Re: [Numpy-discussion] lstsq functionality

2010-07-21 Thread Keith Goodman
On Wed, Jul 21, 2010 at 4:35 PM, Skipper Seabold wrote: > On Tue, Jul 20, 2010 at 10:24 PM, Keith Goodman wrote: >> Good point. Looks like we can get rid of 2 copies! I didn't get rid of >> the second copy but I did cut things down just to see what the timing >> was like. I also threw out the abi

Re: [Numpy-discussion] lstsq functionality

2010-07-21 Thread Skipper Seabold
On Wed, Jul 21, 2010 at 7:25 PM, David Warde-Farley wrote: > On 2010-07-20, at 10:16 PM, Skipper Seabold wrote: > >> Out of curiosity, is there an explicit way to check if these share memory? > > > You could do the exact calculations (I think) but this isn't actually > implemented in NumPy, thoug

Re: [Numpy-discussion] lstsq functionality

2010-07-21 Thread Skipper Seabold
On Tue, Jul 20, 2010 at 10:24 PM, Keith Goodman wrote: > Good point. Looks like we can get rid of 2 copies! I didn't get rid of > the second copy but I did cut things down just to see what the timing > was like. I also threw out the ability to handle complex numbers (only > saves an if iscomplex s

Re: [Numpy-discussion] lstsq functionality

2010-07-21 Thread David Warde-Farley
On 2010-07-20, at 10:16 PM, Skipper Seabold wrote: > Out of curiosity, is there an explicit way to check if these share memory? You could do the exact calculations (I think) but this isn't actually implemented in NumPy, though np.may_share_memory is a conservative test for it that will err on

Re: [Numpy-discussion] Datarray BoF, part2

2010-07-21 Thread Skipper Seabold
On Wed, Jul 21, 2010 at 5:48 PM, Keith Goodman wrote: > On Wed, Jul 21, 2010 at 2:32 PM, Rob Speer wrote: >> I agree with the idea that axis labels must be strings. >> >> Yes, this is the opposite of my position on tick labels ("names"), but >> there's a reason: ticks are often defined by whateve

Re: [Numpy-discussion] doc string linalg.solve --> works for b is matrix

2010-07-21 Thread David Goldsmith
Take it as a reminder: when reporting an error or problem, even if it doesn't seem relevant, always provide version number. :-) DG On Wed, Jul 21, 2010 at 12:50 PM, Mark Bakker wrote: > I am using 1.3.0. > Glad to hear it is correct in 1.4.0 > Sorry for bothering you with an old version, but I

Re: [Numpy-discussion] Datarray BoF, part2

2010-07-21 Thread Keith Goodman
On Wed, Jul 21, 2010 at 2:32 PM, Rob Speer wrote: > I agree with the idea that axis labels must be strings. > > Yes, this is the opposite of my position on tick labels ("names"), but > there's a reason: ticks are often defined by whatever data you happen > to be working with, but axis labels will

Re: [Numpy-discussion] Datarray BoF, part2

2010-07-21 Thread Joshua Holbrook
Make that +2. --Josh On Wed, Jul 21, 2010 at 1:38 PM, Skipper Seabold wrote: > On Wed, Jul 21, 2010 at 5:32 PM, Rob Speer wrote: >> I agree with the idea that axis labels must be strings. >> >> Yes, this is the opposite of my position on tick labels ("names"), but >> there's a reason: ticks are

Re: [Numpy-discussion] Datarray BoF, part2

2010-07-21 Thread Skipper Seabold
On Wed, Jul 21, 2010 at 5:32 PM, Rob Speer wrote: > I agree with the idea that axis labels must be strings. > > Yes, this is the opposite of my position on tick labels ("names"), but > there's a reason: ticks are often defined by whatever data you happen > to be working with, but axis labels will

Re: [Numpy-discussion] Datarray BoF, part2

2010-07-21 Thread Rob Speer
I agree with the idea that axis labels must be strings. Yes, this is the opposite of my position on tick labels ("names"), but there's a reason: ticks are often defined by whatever data you happen to be working with, but axis labels will in the vast majority of situations be defined by the program

Re: [Numpy-discussion] recarray slow?

2010-07-21 Thread wheres pythonmonks
My code had a bug: idx_by_name = dict((n,i) for i,n in enumerate(d.dtype.names)) On Wed, Jul 21, 2010 at 4:49 PM, Pauli Virtanen wrote: > Wed, 21 Jul 2010 16:22:37 -0400, wheres pythonmonks wrote: >> However: is there an automatic way to convert a named index to a >> position? > > It's not rea

Re: [Numpy-discussion] recarray slow?

2010-07-21 Thread Pauli Virtanen
Wed, 21 Jul 2010 16:22:37 -0400, wheres pythonmonks wrote: > However: is there an automatic way to convert a named index to a > position? It's not really a named index -- it's a field name. Since the fields of an array element can be of different size, they cannot be referred to with an array in

Re: [Numpy-discussion] recarray slow?

2010-07-21 Thread Pierre GM
On Jul 21, 2010, at 4:35 PM, wheres pythonmonks wrote: > What about: > > idx_by_name = dict(enumerate(d.dtype.names)) > > Then I can look up the index of the columns I want before the loop, > and then access by the index during the loop. Sure. Why don't you try both approaches, time them and d

Re: [Numpy-discussion] recarray slow?

2010-07-21 Thread wheres pythonmonks
What about: idx_by_name = dict(enumerate(d.dtype.names)) Then I can look up the index of the columns I want before the loop, and then access by the index during the loop. - W On Wed, Jul 21, 2010 at 4:29 PM, Pierre GM wrote: > > On Jul 21, 2010, at 4:22 PM, wheres pythonmonks wrote: > >> How

Re: [Numpy-discussion] recarray slow?

2010-07-21 Thread Pierre GM
On Jul 21, 2010, at 4:22 PM, wheres pythonmonks wrote: > However: is there an automatic way to convert a named index to a position? > > What about looping over tuples of my recarray: > > for t in d: >date = t['Date'] > Why don't you use zip ? >>> for (date, t) in (d['Date'], d) T

Re: [Numpy-discussion] recarray slow?

2010-07-21 Thread wheres pythonmonks
However: is there an automatic way to convert a named index to a position? What about looping over tuples of my recarray: for t in d: date = t['Date'] I guess that the above does have to lookup 'Date' each time. But the following does not need the hash lookup for each tuple: for t

Re: [Numpy-discussion] doc string linalg.solve --> works for b is matrix

2010-07-21 Thread Mark Bakker
I am using 1.3.0. Glad to hear it is correct in 1.4.0 Sorry for bothering you with an old version, but I am very happy with this feature! Mark > What version of numpy are you using? That docstring was updated in that > fashion about 8 mo. ago (at least in the Wiki; I'm not sure exactly when it >

Re: [Numpy-discussion] recarray slow?

2010-07-21 Thread wheres pythonmonks
Thank you very much better crack open a numpy reference manual instead of relying on my python "intuition". On Wed, Jul 21, 2010 at 3:44 PM, Pauli Virtanen wrote: > Wed, 21 Jul 2010 15:12:14 -0400, wheres pythonmonks wrote: > >> I have an recarray -- the first column is date. >> >> I have th

Re: [Numpy-discussion] recarray slow?

2010-07-21 Thread Pauli Virtanen
Wed, 21 Jul 2010 15:12:14 -0400, wheres pythonmonks wrote: > I have an recarray -- the first column is date. > > I have the following function to compute the number of unique dates in > my data set: > > > def byName(): return(len(list(set(d['Date'])) )) What this code does is: 1. d['Date']

Re: [Numpy-discussion] recarray slow?

2010-07-21 Thread Robert Kern
On Wed, Jul 21, 2010 at 15:12, wheres pythonmonks wrote: > I have an recarray -- the first column is date. > > I have the following function to compute the number of unique dates in > my data set: > > > def byName(): return(len(list(set(d['Date'])) )) > > Question:  is the string 'Date' looked up

Re: [Numpy-discussion] Datarray BoF, part2

2010-07-21 Thread Vincent Davis
On Wed, Jul 21, 2010 at 1:00 PM, Keith Goodman wrote: > On Wed, Jul 21, 2010 at 11:41 AM, Vincent Davis > wrote: >> On Wed, Jul 21, 2010 at 11:08 AM, Keith Goodman wrote: >>> On Wed, Jul 21, 2010 at 9:56 AM, John Salvatier >>> wrote: I don't really know much about this topic, but what abou

[Numpy-discussion] recarray slow?

2010-07-21 Thread wheres pythonmonks
I have an recarray -- the first column is date. I have the following function to compute the number of unique dates in my data set: def byName(): return(len(list(set(d['Date'])) )) Question: is the string 'Date' looked up at each iteration? If so, this is dumb, but explains my horrible perfor

Re: [Numpy-discussion] Datarray BoF, part2

2010-07-21 Thread Keith Goodman
On Wed, Jul 21, 2010 at 11:41 AM, Vincent Davis wrote: > On Wed, Jul 21, 2010 at 11:08 AM, Keith Goodman wrote: >> On Wed, Jul 21, 2010 at 9:56 AM, John Salvatier >> wrote: >>> I don't really know much about this topic, but what about a flag at array >>> creation time (or whenever you define lab

Re: [Numpy-discussion] Datarray BoF, part2

2010-07-21 Thread Vincent Davis
On Wed, Jul 21, 2010 at 11:08 AM, Keith Goodman wrote: > On Wed, Jul 21, 2010 at 9:56 AM, John Salvatier > wrote: >> I don't really know much about this topic, but what about a flag at array >> creation time (or whenever you define labels) that says whether valid >> indexes will be treated as lab

Re: [Numpy-discussion] Datarray BoF, part2

2010-07-21 Thread Keith Goodman
On Wed, Jul 21, 2010 at 10:58 AM, M Trumpis wrote: > Separately, regarding the permissible axis labels, I think we must not > allow any enumerated axis labels (ie, ints and floats). I don't > remember if there was a consensus about that yesterday. We don't have > the flexibility in the ndarray AP

Re: [Numpy-discussion] Datarray BoF, part2

2010-07-21 Thread M Trumpis
On Wed, Jul 21, 2010 at 10:08 AM, Keith Goodman wrote: > On Wed, Jul 21, 2010 at 9:56 AM, John Salvatier > wrote: >> I don't really know much about this topic, but what about a flag at array >> creation time (or whenever you define labels) that says whether valid >> indexes will be treated as lab

Re: [Numpy-discussion] Datarray BoF, part2

2010-07-21 Thread Keith Goodman
On Wed, Jul 21, 2010 at 10:41 AM, Bruce Southey wrote: > The current implemented option of allowing strings is the only practical > option and I think that most other related languages also impose this > constraint. Otherwise we will effectively break compatibility with Python > and numpy because

Re: [Numpy-discussion] Datarray BoF, part2

2010-07-21 Thread Bruce Southey
On 07/21/2010 11:56 AM, John Salvatier wrote: I don't really know much about this topic, but what about a flag at array creation time (or whenever you define labels) that says whether valid indexes will be treated as labels or indexes for that array? On Wed, Jul 21, 2010 at 9:37 AM, Keith Good

Re: [Numpy-discussion] Datarray BoF, part2

2010-07-21 Thread Keith Goodman
On Wed, Jul 21, 2010 at 9:56 AM, John Salvatier wrote: > I don't really know much about this topic, but what about a flag at array > creation time (or whenever you define labels) that says whether valid > indexes will be treated as labels or indexes for that array? It's an interesting idea. My gu

Re: [Numpy-discussion] doc string linalg.solve --> works for b is matrix

2010-07-21 Thread David Goldsmith
What version of numpy are you using? That docstring was updated in that fashion about 8 mo. ago (at least in the Wiki; I'm not sure exactly when it was merged, but it does appear that way in version 1.4.0). DG I am using linalg.solve to solve a system of linear equations. As I have to > solve m

Re: [Numpy-discussion] Datarray BoF, part2

2010-07-21 Thread John Salvatier
I don't really know much about this topic, but what about a flag at array creation time (or whenever you define labels) that says whether valid indexes will be treated as labels or indexes for that array? On Wed, Jul 21, 2010 at 9:37 AM, Keith Goodman wrote: > About a dozen people attended what

[Numpy-discussion] Datarray BoF, part2

2010-07-21 Thread Keith Goodman
About a dozen people attended what was billed as a continuation of the SciPy 2010 datarray BoF. We met at UC Berkeley on July 19 as part of the py4science series. A datarray is a subclass of a Numpy array that adds the ability to label the axes and to label the elements along each axis. We spent

Re: [Numpy-discussion] Complete and build the example from the "Using Numpy C-API" documentation.

2010-07-21 Thread Warren Weckesser
Thanks, Pauli. import_array() is what I was missing. Warren Pauli Virtanen wrote: > Tue, 20 Jul 2010 18:04:42 -0500, Warren Weckesser wrote: > [clip] > >> I've made some progress, and now I'm getting a bus error. With the >> following extension module, calling example.foo results in a bus

[Numpy-discussion] doc string linalg.solve --> works for b is matrix

2010-07-21 Thread Mark Bakker
Hello list, I am using linalg.solve to solve a system of linear equations. As I have to solve multiple systems with the same matrix, but different right-hand sides, I tried to make the right-hand side a matrix and that works fine. So the docstring should say: Solve the equation ``a x = b`` fo

Re: [Numpy-discussion] comparing floating point numbers

2010-07-21 Thread Pauli Virtanen
ke, 2010-07-21 kello 10:46 +0200, David Cournapeau kirjoitti: [clip: assert nulps] > I think we should go toward using those almost everywhere we need > floating point comparison in testing, I think we also need an assertion function that behaves like np.allclose -- the ULPs are somewhat unintuiti

Re: [Numpy-discussion] comparing floating point numbers

2010-07-21 Thread David Cournapeau
On Tue, Jul 20, 2010 at 3:31 AM, Ondrej Certik wrote: > Hi, > > I was always using something like > > abs(x-y) < eps > > or > > (abs(x-y) < eps).all() > > but today I needed to also make sure this works for larger numbers, > where I need to compare relative errors, so I found this: > > http://www.

Re: [Numpy-discussion] comparing floating point numbers

2010-07-21 Thread Ondrej Certik
Hi Keith! On Mon, Jul 19, 2010 at 6:40 PM, Keith Goodman wrote: > On Mon, Jul 19, 2010 at 6:31 PM, Ondrej Certik wrote: >> Hi, >> >> I was always using something like >> >> abs(x-y) < eps >> >> or >> >> (abs(x-y) < eps).all() >> >> but today I needed to also make sure this works for larger numbe

Re: [Numpy-discussion] Complete and build the example from the "Using Numpy C-API" documentation.

2010-07-21 Thread Pauli Virtanen
Tue, 20 Jul 2010 18:04:42 -0500, Warren Weckesser wrote: [clip] > I've made some progress, and now I'm getting a bus error. With the > following extension module, calling example.foo results in a bus error, > regardless of the arguments given. The error occurs in the call to > PyArg_ParseTuple.

[Numpy-discussion] inverse of compress

2010-07-21 Thread Vincent Schut
Hi, I find myself often looking for a numpy function that would behave like an inverse compress. E.g. one that satisfies a.compress(mask) = b, given b and mask, creating a. Or like a createFromMask function, which would create an array with shape of a given boolean mask, and filling all elemen