Re: [Numpy-discussion] array from list of lists

2006-11-12 Thread Erin Sheldon
On 11/13/06, Charles R Harris <[EMAIL PROTECTED]> wrote: > > > On 11/12/06, Erin Sheldon <[EMAIL PROTECTED]> wrote: > > Hi all - > > > > Thanks to everyone for the suggestions. > > I think map(tuple, list) is probably the most compact, > > but the list comprehension also works well. > > > > Because

Re: [Numpy-discussion] array from list of lists

2006-11-12 Thread Charles R Harris
On 11/12/06, Erin Sheldon <[EMAIL PROTECTED]> wrote: Hi all -Thanks to everyone for the suggestions.I think map(tuple, list) is probably the most compact,but the list comprehension also works well.Because map() is proably going to disappear someday, I'll stick with the list comprehension.  array( [

Re: [Numpy-discussion] array from list of lists

2006-11-12 Thread Erin Sheldon
Hi all - Thanks to everyone for the suggestions. I think map(tuple, list) is probably the most compact, but the list comprehension also works well. Because map() is proably going to disappear someday, I'll stick with the list comprehension. array( [tuple(row) for row in result], dtype=dtype) T

Re: [Numpy-discussion] array from list of lists

2006-11-12 Thread Robert Kern
Pierre GM wrote: > On Sunday 12 November 2006 20:10, Erin Sheldon wrote: >> Actually, there is a problem with that approach. It first converts >> the entire array to a single type, by default a floating type. > > As A.M. Archibald suggested, you can use list comprehension: > N.array([(a,b,c,d,)

Re: [Numpy-discussion] array from list of lists

2006-11-12 Thread Pierre GM
On Sunday 12 November 2006 20:10, Erin Sheldon wrote: > Actually, there is a problem with that approach. It first converts > the entire array to a single type, by default a floating type. As A.M. Archibald suggested, you can use list comprehension: N.array([(a,b,c,d,) for (a,b,c,d) in yourlist]

Re: [Numpy-discussion] array from list of lists

2006-11-12 Thread Tim Hochberg
Erin Sheldon wrote: > On 11/12/06, Tim Hochberg <[EMAIL PROTECTED]> wrote: > >> I haven't been following this too closely, but if you need to transpose >> your data without converting all to one type, I can think of a couple of >> different approaches: >> >> 1. zip(*yourlist) >> 2. nump

Re: [Numpy-discussion] Equivalent to list.index ?

2006-11-12 Thread Tim Hochberg
George Sakkis wrote: > Tim Hochberg wrote: > > >> George Sakkis wrote: >> >>> def index(a, value): >>> return N.where(a==value)[0][0] >>> >>> >> Or >> >> def index(a, value): >> return argmax(a == value) >> > > That's a bit easier to write and a bit harder to grok; that'

Re: [Numpy-discussion] Equivalent to list.index ?

2006-11-12 Thread George Sakkis
Tim Hochberg wrote: > George Sakkis wrote: > > def index(a, value): > > return N.where(a==value)[0][0] > > > Or > > def index(a, value): > return argmax(a == value) That's a bit easier to write and a bit harder to grok; that's ok, I can live with it. > > This works but seems clunky and l

Re: [Numpy-discussion] array from list of lists

2006-11-12 Thread A. M. Archibald
On 12/11/06, Erin Sheldon <[EMAIL PROTECTED]> wrote: > Actually, there is a problem with that approach. It first converts > the entire array to a single type, by default a floating type. For > very large integers this precision is insufficient. For example, I > have the following integer in my

Re: [Numpy-discussion] array from list of lists

2006-11-12 Thread Erin Sheldon
On 11/12/06, Tim Hochberg <[EMAIL PROTECTED]> wrote: > I haven't been following this too closely, but if you need to transpose > your data without converting all to one type, I can think of a couple of > different approaches: > > 1. zip(*yourlist) > 2. numpy.transpose(numpy.array(yourlist,

Re: [Numpy-discussion] array from list of lists

2006-11-12 Thread Tim Hochberg
Erin Sheldon wrote: > On 11/12/06, Erin Sheldon <[EMAIL PROTECTED]> wrote: > >> On 11/12/06, Pierre GM <[EMAIL PROTECTED]> wrote: >> >>> You could try the fromarrays function of numpy.core.records >>> >>> >> mydescriptor = {'names': (a','b','c','d'), 'formats':('f4', 'f4', 'f4',

Re: [Numpy-discussion] Compiling numpy with lapack and atlas

2006-11-12 Thread Abhishek Roy
--- Robert Kern <[EMAIL PROTECTED]> wrote: > Also add g2c to your library list, then. It is g77's FORTRAN runtime library Okay I put libg2c.a in the atlas directory and made the line in site.cfg, atlas_libs = lapack, f77blas, cblas, atlas, g2c Now numpy imports but numpy.linalg.test() as well as a

Re: [Numpy-discussion] array from list of lists

2006-11-12 Thread Erin Sheldon
On 11/12/06, Charles R Harris <[EMAIL PROTECTED]> wrote: > > 94137100072000193L > > which ends up as > > 94137100072000192 > > after going to a float and then back to an integer. > > Out of curiosity, where does that large integer come from? It is a unique object identifier. It is a combination

Re: [Numpy-discussion] array from list of lists

2006-11-12 Thread Charles R Harris
On 11/12/06, Erin Sheldon <[EMAIL PROTECTED]> wrote: On 11/12/06, Erin Sheldon <[EMAIL PROTECTED]> wrote:> On 11/12/06, Pierre GM <[EMAIL PROTECTED]> wrote:> > > > You could try the fromarrays function of numpy.core.records> >> > >>> mydescriptor = {'names': (a','b','c','d'), 'formats':('f4', 'f4',

Re: [Numpy-discussion] array from list of lists

2006-11-12 Thread Erin Sheldon
On 11/12/06, Erin Sheldon <[EMAIL PROTECTED]> wrote: > On 11/12/06, Pierre GM <[EMAIL PROTECTED]> wrote: > > > > You could try the fromarrays function of numpy.core.records > > > > >>> mydescriptor = {'names': (a','b','c','d'), 'formats':('f4', 'f4', 'f4', > > 'f4')} > > >>> a = N.core.records.from

Re: [Numpy-discussion] array from list of lists

2006-11-12 Thread Erin Sheldon
On 11/12/06, Pierre GM <[EMAIL PROTECTED]> wrote: > > You could try the fromarrays function of numpy.core.records > > >>> mydescriptor = {'names': (a','b','c','d'), 'formats':('f4', 'f4', 'f4', > 'f4')} > >>> a = N.core.records.fromarrays(N.transpose(yourlist), dtype=mydescriptor) > > The 'transpos

Re: [Numpy-discussion] array from list of lists

2006-11-12 Thread Pierre GM
You could try the fromarrays function of numpy.core.records >>> mydescriptor = {'names': (a','b','c','d'), 'formats':('f4', 'f4', 'f4', 'f4')} >>> a = N.core.records.fromarrays(N.transpose(yourlist), dtype=mydescriptor) The 'transpose' function ensures that 'fromarrays' sees 4 arrays (one for e

Re: [Numpy-discussion] array from list of lists

2006-11-12 Thread Erin Sheldon
I have to not ammend my statement a bit: DBI 2.0 actually returns a lists of tuples, which would work. It appears to just be pgdb, the postgres interface, that is returning lists of lists. Still, I need to interact with this database. Erin On Sun, Nov 12, 2006 at 06:56:29PM -0500, Erin Sheld

[Numpy-discussion] array from list of lists

2006-11-12 Thread Erin Sheldon
Hi all- I want to take the result from a database query, and create a numpy array with field names and types corresponding to the returned columns. The DBI 2.0 compliant interfaces return lists of lists. E.g. [[94137100072000193L, 94, 345.5721510002, -0.8367320809996], [94137100072000

Re: [Numpy-discussion] Compiling numpy with lapack and atlas

2006-11-12 Thread Robert Kern
Abhishek Roy wrote: > --- Robert Kern <[EMAIL PROTECTED]> wrote: >> Are your ATLAS libraries shared or static (i.e., are they libatlas.so or >> libatlas.a)? ldd(1) only lists the shared libraries that are linked. ATLAS is >> usually installed as static libraries. > They are static. Thanks, I was mi

Re: [Numpy-discussion] Could numpy.matlib.nanmax return a matrix?

2006-11-12 Thread Pierre GM
On Sunday 12 November 2006 17:08, A. M. Archibald wrote: > On 12/11/06, Keith Goodman <[EMAIL PROTECTED]> wrote: > > Is anybody interested in making x.max() and nanmax() behave the same > > for matrices, except for the NaN part? That is, make > > numpy.matlib.nanmax return a matrix instead of an ar

Re: [Numpy-discussion] Equivalent to list.index ?

2006-11-12 Thread Colin J. Williams
Tim Hochberg wrote: George Sakkis wrote: def index(a, value): return N.where(a==value)[0][0] Or def index(a, value): return argmax(a == value) This works but seems clunky and less efficient than necessary. If there isn't a better alternative, I w

Re: [Numpy-discussion] Could numpy.matlib.nanmax return a matrix?

2006-11-12 Thread A. M. Archibald
On 12/11/06, Keith Goodman <[EMAIL PROTECTED]> wrote: > Is anybody interested in making x.max() and nanmax() behave the same > for matrices, except for the NaN part? That is, make > numpy.matlib.nanmax return a matrix instead of an array. Sounds good to me; maybe put a patch in the tracker? A. M.

[Numpy-discussion] Could numpy.matlib.nanmax return a matrix?

2006-11-12 Thread Keith Goodman
Is anybody interested in making x.max() and nanmax() behave the same for matrices, except for the NaN part? That is, make numpy.matlib.nanmax return a matrix instead of an array. Example = >> import numpy.matlib as M >> x = M.rand(3,2) >> x.max(0) matrix([[ 0.91749823, 0.94942954]]) >> M.n

Re: [Numpy-discussion] Equivalent to list.index ?

2006-11-12 Thread Tim Hochberg
George Sakkis wrote: > def index(a, value): > return N.where(a==value)[0][0] > Or def index(a, value): return argmax(a == value) > This works but seems clunky and less efficient than necessary. If there > isn't a better alternative, I would welcome a new index() > function/method in t

Re: [Numpy-discussion] Compiling numpy with lapack and atlas

2006-11-12 Thread Abhishek Roy
--- Robert Kern <[EMAIL PROTECTED]> wrote: > Are your ATLAS libraries shared or static (i.e., are they libatlas.so or > libatlas.a)? ldd(1) only lists the shared libraries that are linked. ATLAS is > usually installed as static libraries. They are static. Thanks, I was mindlessly copying a suggesti

Re: [Numpy-discussion] Equivalent to list.index ?

2006-11-12 Thread George Sakkis
Keith Goodman wrote: > On 11/12/06, George Sakkis <[EMAIL PROTECTED]> wrote: > > This must be pretty trivial but I couldn't find it in the docs: what's > > the "numpythonic" way to find the (first) index of an element, i.e. the > > equivalent to list.index ? > > Does where work? def index(a, valu

Re: [Numpy-discussion] I can slice but I can't assign

2006-11-12 Thread Keith Goodman
On 11/12/06, Keith Goodman <[EMAIL PROTECTED]> wrote: > >> x = M.matrix([[1, 2], [3, 4]]) > >> x > matrix([[1, 2], > [3, 4]]) > > >> y = M.matrix([[5], [6]]) > >> y > matrix([[5], > [6]]) > > >> idx = M.where(x[:,0].A < 100)[0] > >> idx > array([0, 1]) > > > >> x[idx,0] # < Th

[Numpy-discussion] I can slice but I can't assign

2006-11-12 Thread Keith Goodman
>> x = M.matrix([[1, 2], [3, 4]]) >> x matrix([[1, 2], [3, 4]]) >> y = M.matrix([[5], [6]]) >> y matrix([[5], [6]]) >> idx = M.where(x[:,0].A < 100)[0] >> idx array([0, 1]) >> x[idx,0] # < This works matrix([[1], [3]]) >> x[idx,0] = y# < But this doesn't w

Re: [Numpy-discussion] Equivalent to list.index ?

2006-11-12 Thread Keith Goodman
On 11/12/06, George Sakkis <[EMAIL PROTECTED]> wrote: > This must be pretty trivial but I couldn't find it in the docs: what's > the "numpythonic" way to find the (first) index of an element, i.e. the > equivalent to list.index ? Does where work? --

[Numpy-discussion] Equivalent to list.index ?

2006-11-12 Thread George Sakkis
This must be pretty trivial but I couldn't find it in the docs: what's the "numpythonic" way to find the (first) index of an element, i.e. the equivalent to list.index ? Thanks, George - Using Tomcat but need to do more? Nee

Re: [Numpy-discussion] Helper function to "unroll" a array

2006-11-12 Thread Gael Varoquaux
You're probably right. Well it would most definitely be useful for all the lads in my lab, but I am not sure this is a broad audience. The use case is when you have a array representing data in an "mgrid" way, and you wnat to apply transformations to the coordinates. It is something I have done and

Re: [Numpy-discussion] Helper function to "unroll" a array

2006-11-12 Thread Sven Schreiber
Gael Varoquaux schrieb: > Hi all, > > I didn't get any answers to this email. Is it because the proposed > addition to numpy is not of any interest to anybody apart from me ? > Maybe the way I introduced this is wrong. Please tell me what is wrong > with this proposition. > Well you didn't m

Re: [Numpy-discussion] Helper function to "unroll" a array

2006-11-12 Thread Gael Varoquaux
Hi all, I didn't get any answers to this email. Is it because the proposed addition to numpy is not of any interest to anybody apart from me ? Maybe the way I introduced this is wrong. Please tell me what is wrong with this proposition. Regards, Gaël On Fri, Oct 20, 2006 at 01:28:52PM +0200

Re: [Numpy-discussion] Compiling numpy with lapack and atlas

2006-11-12 Thread Neal Becker
I see you're on linux. If this is Fedora, atlas (and the other libaries) are available from standard repos (core + extras) - Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly wi