From templon@studbolt.mit.edu Thu May 2 19:17:19 1996 From: templon@studbolt.mit.edu (Jeff Templon) Date: Thu, 2 May 1996 14:17:19 -0400 Subject: [PYTHON MATRIX-SIG] any matlab-like python extensions??? Message-ID: <199605021817.OAA00861@studbolt.mit.edu> Hi, I had posted the following on comp.lang.python, but someone pointed out that it was better posted here. Since my newsgroup posting, I've heard from at least one other person who is interested in the results. Below is the content of my comp.lang.python post. Please respond to me via email, as I am not on the matrix-sig list (perhaps yet.) Also, please cc your message to Alex Cannon who is also very interested in what you have to say. Jeff Templon wrote: > > Hi, > > I'm looking to do some numerical programming, and would like to do it > in Python. I know about the new Matrix-SIG activities, but I am also > interested in a graphical display of the results. I've looked at SciLab, > which is a sort of PD version of Matlab, and this is exactly what > I'm looking for except it's not Python (although a lot of the syntax > is close!) > > The thing in SciLab that Python (as far as I know) is missing, is a > package of plotting primitives. In Scilab, you can say something like > "plot (vector1, vector2)" where vector1 is some array of x values and > vector2 is an array of y values; you can also give three vectors and > get a surface or contour plot (or even both, with the contour plot > overlaid on the surface!) Is there anything like this for Python? > I'd guess it'd be interfaced to Tk or SUIT or somesuch. > > I know I could do a poor-man's interface using a pipe to Gnuplot. > I'm considering that as a first step. Any info on products or > things in the works is welcomed. > > Jeff Templon ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From tschwal@artinet.de Thu May 2 21:32:45 1996 From: tschwal@artinet.de (Tom Schwaller) Date: Thu, 2 May 1996 22:32:45 +0200 (MET DST) Subject: [PYTHON MATRIX-SIG] any matlab-like python extensions??? In-Reply-To: <199605021817.OAA00861@studbolt.mit.edu> Message-ID: Hi Jeff, well try the plplotmodule I've written (interfaces the plplot library). It is not pefect, but has a Tk widget with it, which no other package has. I one worked on a Python module interfacing the Visual toolkit++, which is a very tool cool, but I'm a little bit short in time for it. Otherwise you can also try the OpenGL module By myself and Jim H.) Join this group, that's the right place for you. Here you will also learn about where to get all that stuff and ther are many people , which will help you I guess. BTW. Have some of you tried out pgplot (Fortran library, no Tk widget, but very nice output, Interfacing it to Python is as easy as plplot, somebody going to do it? There's already a Tcl and Perl Module (I hear you SWIG! :-) We should at least do a Python module. Look at the URL http://astro.caltech.edu/~tjp/pgplot/ Comments Tom ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From da@maigret.cog.brown.edu Thu May 2 22:01:52 1996 From: da@maigret.cog.brown.edu (David Ascher) Date: Thu, 2 May 1996 17:01:52 -0400 (EDT) Subject: [PYTHON MATRIX-SIG] any matlab-like python extensions??? In-Reply-To: from "Tom Schwaller" at May 2, 96 10:32:45 pm Message-ID: <199605022101.RAA09570@maigret> > BTW. Have some of you tried out pgplot (Fortran library, no Tk widget, > but very nice output, Interfacing it to Python is as easy as plplot, > somebody going to do it? > There's already a Tcl and Perl Module (I hear you SWIG! :-) > We should at least do a Python module. > Look at the URL > http://astro.caltech.edu/~tjp/pgplot/ I'll look at it. My favorite output (sober but very professional) comes out of GLE, which alas is nothing one can interface to easily. --david ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From da@maigret.cog.brown.edu Wed May 8 19:41:46 1996 From: da@maigret.cog.brown.edu (David Ascher) Date: Wed, 8 May 1996 14:41:46 -0400 (EDT) Subject: [PYTHON MATRIX-SIG] Tela/Python conversion help needed Message-ID: <199605081841.OAA22407@maigret> Hi folks. I've ported the fftpack routines which are part of Tela into a python module, which is fine. Now I need to port a little piece of Tela code which does the n-dimensional fft's out of the 1-d fft routines. I've given it a try, but my nonexistent knowledge of tela and my lack of experience with multidimensional fft's makes it a hard thing for me to debug. Does anyone out there feel willing to help me with this conversion? Let me know. --david PS: Tela seems to have a nice set of routines which I'd like to see in Python. What do you think? From the "Tela Feature List": ----------------------------------------------------------------------- Linear algebra: matrix inversion, matrix product, eigenvalues, eigenvectors, determinant, LU, Cholesky, singular value decompositions and linear system solution. Full set of fast Fourier transform routines. In addition to ordinary complex and real FFTs there are sine, cosine, plus quarter-wave sine and cosine transforms. All routines can work along any dimension in an N-dimensional real or complex array, making it possible e.g. to solve any constant-coefficient elliptic boundary value problem in 2D or 3D with any boundary conditions (Dirichlet, Neumann or periodic type; each boundary may have its own type of boundary condition). An example how this is done is included in the distribution (testpoisson.t). Unix commands can be run under Tela control. Standard input and output can be mapped to Tela strings. C stdio like functions for manipulating files. Can work with HDF, netCDF (vers.>=1.23), plain ASCII, MATLAB binary files (MAT-files) and PBM (PPM, PGM) image files directly. Graphics can be saved as PostScript and GIF from the PlotMTV program. Can interface to XV. Graphics: 2D and 3D line and curve plots, contour plots, density plots, vector field plots and surface plots. Cartesian intersection surfaces in 3D space. Bar charts and histograms. Possibility to redraw existing windows or create new window for each new plot. Possibilities for overlaying and stacking plots and saving them in PostScript or GIF files. Possibility to annotate plots with text strings and simple geometric primitives. Palette can be changed and nonuniform grids can be used (vers>=1.23). Numerical analysis: linear interpolation (intpol), integration (integrate), function minimization (fmin), root finding (roots, fsolve), linear regression (fitline, fitlinear), nonlinear fitting (fitnl). Preliminary version of special function package (specfun.t), which contains a relatively complete set of special functions. ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From da@bekas.cog.brown.edu Wed May 8 20:50:02 1996 From: da@bekas.cog.brown.edu (David Ascher) Date: Wed, 8 May 1996 15:50:02 -0400 (EDT) Subject: [PYTHON MATRIX-SIG] remind me Message-ID: <199605081950.PAA07821@bekas> Is there a shorthand for: x2 = ravel(x) x2[n] = v x2.shape = x.shape x = x2 ? --da ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From hinsenk@ERE.UMontreal.CA Wed May 8 21:37:20 1996 From: hinsenk@ERE.UMontreal.CA (Konrad HINSEN) Date: Wed, 8 May 1996 16:37:20 -0400 Subject: [PYTHON MATRIX-SIG] remind me In-Reply-To: <199605081950.PAA07821@bekas> (message from David Ascher on Wed, 8 May 1996 15:50:02 -0400 (EDT)) Message-ID: <199605082037.QAA28375@cyclone.ERE.UMontreal.CA> > Is there a shorthand for: > > x2 = ravel(x) > x2[n] = v > x2.shape = x.shape > x = x2 The way ravel() is implemented now, the first two lines should be enough, i.e. they should change x. My API proposal contains a feature that would allow this to be written as x[......][n] = v I don't think you can get it much shorter... ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsenk@ere.umontreal.ca Departement de chimie | Tel.: +1-514-343-6111 ext. 3953 Universite de Montreal | Fax: +1-514-343-7586 C.P. 6128, succ. Centre-Ville | Deutsch/Esperanto/English/Nederlands/ Montreal (QC) H3C 3J7 | Francais (phase experimentale) ------------------------------------------------------------------------------- ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From da@maigret.cog.brown.edu Wed May 15 01:03:04 1996 From: da@maigret.cog.brown.edu (David Ascher) Date: Tue, 14 May 1996 20:03:04 -0400 (EDT) Subject: [PYTHON MATRIX-SIG] arange w/ fixed # of elements? Message-ID: <199605150003.UAA12840@maigret> What is the recommended way to get an arange of a given # of elements between a min & and max? If I do: step = (max - min) / float(number) r = arange(min, max, step) then I am sometimes getting arrays w/ number + 1 elements, due to the odd case when max and min are exactly (or close enough) divisible by the stepsize. So, the following: from Numeric import * def test(s): x = 1.2*pi / s n = 300 st = x / 300 if len(arange(0,x,st)) == 301: print s for x in arange(-5,5,.05): if x != 0: test(x) shows that test(-0.8) and test(-1.6) on my machine yield arrays of size 301, while all the others yield arrays of size 300. ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From hinsenk@ere.umontreal.ca Wed May 15 02:07:15 1996 From: hinsenk@ere.umontreal.ca (Konrad HINSEN) Date: Tue, 14 May 1996 21:07:15 -0400 Subject: [PYTHON MATRIX-SIG] arange w/ fixed # of elements? In-Reply-To: <199605150003.UAA12840@maigret> (da@maigret.cog.brown.edu) Message-ID: <199605150107.VAA29247@cyclone.ERE.UMontreal.CA> > What is the recommended way to get an arange of a given # of elements > between a min & and max? > > If I do: > step = (max - min) / float(number) > r = arange(min, max, step) > > then I am sometimes getting arrays w/ number + 1 elements, due to > the odd case when max and min are exactly (or close enough) divisible > by the stepsize. Try: min+(max-min)*arange(number)/number There are no problems with roundoff error in this case. ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsenk@ere.umontreal.ca Departement de chimie | Tel.: +1-514-343-6111 ext. 3953 Universite de Montreal | Fax: +1-514-343-7586 C.P. 6128, succ. Centre-Ville | Deutsch/Esperanto/English/Nederlands/ Montreal (QC) H3C 3J7 | Francais (phase experimentale) ------------------------------------------------------------------------------- ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From barton@simsg1.mdc.com Wed May 15 19:05:42 1996 From: barton@simsg1.mdc.com (Brien Barton) Date: Wed, 15 May 1996 11:05:42 -0700 (PDT) Subject: [PYTHON MATRIX-SIG] Where is source? Message-ID: Where can I get the numeric extension for Python? I looked all over the python.org web site and can't find it. =============================================================================== Brien Barton McDonnell Douglas Aerospace, Huntington Beach, CA email: barton@simvx1.mdc.com, voice: (714)896-2249, fax:(714)896-5939 ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From jjh@goldilocks.lcs.mit.edu Wed May 15 19:22:46 1996 From: jjh@goldilocks.lcs.mit.edu (James Hugunin) Date: Wed, 15 May 96 14:22:46 EDT Subject: [PYTHON MATRIX-SIG] Reposting of the FAQ Message-ID: <9605151822.AA16460@baribal.LCS.MIT.EDU.LCS.MIT.EDU> This FAQ needs to be updated, and should be put on the web somewhere so that I can just put a pointer here occasionally. But, until the semester is over here that's not going to happen, so here's my brief FAQ again for newbies to the list. (To the rest of you I apologize). -Jim Written by Jim Hugunin (hugunin@mit.edu) on April 25, 1996. 1) What's Numerical Python? Here should really go Paul's humorous depiction of Monty's more serious brother, but I don't have that right now, so the high level stuff will have to wait. 2) Where do I get it? ftp://sls-ftp.lcs.mit.edu/pub/jjh/NumericalPython-0.36.tar.gz This is the latest version. New versions will be made available at this location. 3) Is there any documentation? There's incomplete online documentation written by David Ascher for a course he taught using Numerical Python at: http://maigret.cog.brown.edu/python/arraytut.html There's a paper soon to be published in Computers and Physics written by Dubois, Hinsen and Hugunin at: ftp://ftp-icf.llnl.gov/pub/basis/numerical_python.ps There's my talk from the 3rd python workshop at: http://www.python.org/workshops/1995-12/papers/hugunin.html 4) What modules are available that use Numerical python? (Note: I know that this needs pointers, I just don't have the time to put them together today) Tom Schwaller's delaunaymodule and trimodule Tom's and my opengl, glu, and glut modules Paul DuBois' URNGmodule Doug Heisterkamp's interface to the LAPACK libraries at: ftp://ftp.cs.unl.edu/pub/drh/python/pylapack.0.02.tar.gz 5) What are the future plans? First goal is a general release to the python community. Before this happens, I want a somewhat finalized API (which Konrad seems to have provided) implemented (for which I just need some free time). I don't want to have too many users developing code with the system before the API is at least closer to its final form (to minimize the changes they need to make). On the other hand, the C API is essentially final. I'm perfectly willing to guarantee that I won't introduce any major incompatibilities in subsequent release of the system. This means that people have no excuse not to develop modules to interface to all that great C/FORTRAN numerical code out there. Obviously the ultimate goal is to have this a part of the base python distribution. I'll start thinking more about this once I make the general release to the community at large. 6) Hints for Windows Users You must use binary mode files for pickling and unpickling matrices in the windows world. Blame Bill for the silliness. ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From klm@CNRI.Reston.Va.US Wed May 15 19:51:02 1996 From: klm@CNRI.Reston.Va.US (Ken Manheimer) Date: Wed, 15 May 1996 14:51:02 -0400 (EDT) Subject: [PYTHON MATRIX-SIG] Reposting of the FAQ In-Reply-To: <9605151822.AA16460@baribal.LCS.MIT.EDU.LCS.MIT.EDU> Message-ID: I've added the FAQ and a blurb about it to the matrix-sig index page: Jim - how about creating a symlink to the latest version of the distribution, so the links in the FAQ, etc, can refer to it, and not need to be changed when the version changes? Eg: ftp://sls-ftp.lcs.mit.edu/pub/jjh/NumericalPython.tar.gz rather than ftp://sls-ftp.lcs.mit.edu/pub/jjh/NumericalPython-0.36.tar.gz (Soon SIG managers will be able to upload and arrange their python.org SIG dirs via anonymous ftp, incidentally, making this kind of info dissemination much more fluid, i hope.) Ken Manheimer klm@cnri.reston.va.us 703 620-8990 x268 (orporation for National Research |nitiatives 1895 Preston White Drive, Suite 100 Reston, VA 22091 ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From Marko Balabanovic Fri May 17 02:14:21 1996 From: Marko Balabanovic (Marko Balabanovic) Date: Thu, 16 May 96 18:14:21 PDT Subject: [PYTHON MATRIX-SIG] Compact Representation? Message-ID: I'm kind of an amateur at linear algebra, so this may be a stupid question: Is there already, or are there any plans to include, a compact representation for sparse or symmetric matrices in Numeric Python (possibly with interfaces to the LAPACK/CLAPACK routines which work with a packed representation for symmetric matrices). I have an approx. 10,000 x 10,000 symmetric matrix, all values are 1 or 0, and I need to get the first couple of eigenvectors. If anyone has any pointers to code that would help do this without needing to construct the whole thing in memory at once I would be very grateful. Marko .Marko Balabanovic.......Department of Computer Science.................... .Stanford University Email: marko@cs.stanford.edu Office: Gates 132 . .Gates Building 1A Phone: 415 725 8783 Fax: 415 725 1449 . .Stanford CA 94305-9010 Url: http://robotics.stanford.edu/people/marko . .USA....................................................................... ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From hinsenk@ere.umontreal.ca Fri May 17 14:47:59 1996 From: hinsenk@ere.umontreal.ca (Konrad HINSEN) Date: Fri, 17 May 1996 09:47:59 -0400 Subject: [PYTHON MATRIX-SIG] Compact Representation? In-Reply-To: (message from Marko Balabanovic on Thu, 16 May 96 18:14:21 PDT) Message-ID: <199605171347.JAA16768@cyclone.ERE.UMontreal.CA> > Is there already, or are there any plans to include, a compact > representation for sparse or symmetric matrices in Numeric Python > (possibly with interfaces to the LAPACK/CLAPACK routines which work > with a packed representation for symmetric matrices). Support for symmetric packed matrices is on my to-do-list for the high-level LAPACK interface, but I won't make any promises about when this is going to happen. I am not even quite sure about how to handle such matrices. I certainly don't want to take the Fortran-like approach of considering packed matrices like 1D-arrays and leaving indexing etc. to the user. So there will be a class representing symmetric matrices, and the LAPACK-interface will select the suitable LAPACK-routine. But how this will work in detail also depends on what mechanisms will be available in the final array package for defining array-like Python classes and making array functions available on them. > I have an approx. 10,000 x 10,000 symmetric matrix, all values are 1 > or 0, and I need to get the first couple of eigenvectors. If anyone > has any pointers to code that would help do this without needing to > construct the whole thing in memory at once I would be very grateful. In that case LAPACK won't help you. You should look at the iterative eigenvalue algorithms that only require a routine to to matrix-vector multiplication. In writing this routine you could even take advantage of having only two different elements in the matrix. But this will end up in very specialized code, probably best done in a small C extension module interfacing to the array module. ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsenk@ere.umontreal.ca Departement de chimie | Tel.: +1-514-343-6111 ext. 3953 Universite de Montreal | Fax: +1-514-343-7586 C.P. 6128, succ. Centre-Ville | Deutsch/Esperanto/English/Nederlands/ Montreal (QC) H3C 3J7 | Francais (phase experimentale) ------------------------------------------------------------------------------- ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From da@maigret.cog.brown.edu Tue May 21 23:15:19 1996 From: da@maigret.cog.brown.edu (David Ascher) Date: Tue, 21 May 1996 18:15:19 -0400 (EDT) Subject: [PYTHON MATRIX-SIG] bug, I claim Message-ID: <199605212215.SAA14621@maigret> That the following happens is, I believe, unfortunate: from Numeric import * from Ranf import * a = random_sample(10) b = (a.greater(0.5).choose(0,0.1)) print b 0 0 0 0 0 0 0 0 0 0 c = (a.greater(0.5).choose(0.0,0.1)) print c 0.10000000 0.10000000 0.10000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.10000000 0.00000000 Why should the type of the first argument to choose() be valued over the most generic type? ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From pas@lems.brown.edu Wed May 22 15:43:42 1996 From: pas@lems.brown.edu (Perry A. Stoll) Date: Wed, 22 May 1996 10:43:42 -0400 (EDT) Subject: [PYTHON MATRIX-SIG] bug and fix for Numeric.where Message-ID: While were looking at bugs... I finally understand the beauty of the Numeric.where function (and the "choose" function, but that's a separate story). But I think the function in Numeric is wrong. Here's a replacement. The function is pretty trivial, but I like the way it reads in code and vote for keeping it. def where(condition, x, y): """where(condition,x,y) is shaped like condition and has elements of x and y where condition is respectively true or false """ return condition.choose(y, x) # removed condition as first argument As a test demonstrating the problem and fix: Select elements from either a or b, which ever is greater - exactly what the "where" function is for. >>> import Numeric >>> a = Numeric.arange(10) >>> b = Numeric.zeros(10,'l') + 4 >>> Numeric.where(a.greater(b),a,b) 0 0 0 0 0 4 4 4 4 4 # huh?? >>> where(a.greater(b),a,b) 4 4 4 4 4 5 6 7 8 9 # ahhh, that's better. -Perry ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From jjh@goldilocks.lcs.mit.edu Wed May 22 16:05:34 1996 From: jjh@goldilocks.lcs.mit.edu (James Hugunin) Date: Wed, 22 May 96 11:05:34 EDT Subject: [PYTHON MATRIX-SIG] bugs Message-ID: <9605221505.AA00341@baribal.LCS.MIT.EDU.LCS.MIT.EDU> Perry Stoll suggests a small bug in the where function, and he's of course correct. The change has been made. def where(condition, x, y): """where(condition,x,y) is shaped like condition and has elements of x and y where condition is respectively true or false """ return condition.choose(y, x) # removed condition as first argument This and similar functions will be retained in the great renaming that is beginning even as we speak. They might, however, be moved to a shortcuts module that wouldn't always be automatically loaded. -- David Ascher's bug is a little more troublesome, but it too is being fixed. > Why should the type of the first argument to choose() be valued over the > most generic type? In short, it shouldn't, and it won't in the next release. -Jim ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From martin@ipc2ibm1.chemie.uni-karlsruhe.de Thu May 23 09:18:39 1996 From: martin@ipc2ibm1.chemie.uni-karlsruhe.de (MARTIN GEGENHEIMER AK kappes) Date: Thu, 23 May 1996 10:18:39 +0200 (MSZ) Subject: [PYTHON MATRIX-SIG] [Q] Array->String conversion, how? Message-ID: <9605230818.AA26109@ipc2ibm1.chemie.uni-karlsruhe.de> Hello, I think I need som help: I'd like to convert a numeric array to a string like (to pass it to Tcl) { 1.0 2.0 .... } I tried : str(), repr(), but that gives me : "array([0,1,2,3,4,5,6,7,8,9], 'l')" a.toList() is much more what I want (its also fast for larger arrays) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] but I don't want ',' or braces. a.toString() does no do what I want. so, how ? maybe make a modified toList() ? -- Martin Gegenheimer Institut fuer Physikalische Chemie II Kaiserstr.12 76128 Karlsruhe Germany home-page: http://www.chemie.uni-karlsruhe.de/~martin e-mail: martin@ipc2ibm1.chemie.uni-karlsruhe.de voice: ++49 721 608-3255 fax : ++49 721 608-3310 ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From martin@ipc2ibm1.chemie.uni-karlsruhe.de Thu May 23 12:51:45 1996 From: martin@ipc2ibm1.chemie.uni-karlsruhe.de (MARTIN GEGENHEIMER AK kappes) Date: Thu, 23 May 1996 13:51:45 +0200 (MSZ) Subject: [PYTHON MATRIX-SIG] [Q] Array->String conversion, how? Message-ID: <9605231151.AA05001@ipc2ibm1.chemie.uni-karlsruhe.de> Forwarded message: > From root Thu May 23 13:42:41 1996 > Date: Thu, 23 May 96 07:37:58 EDT > Message-Id: <9605231137.AA02767@acdc.eeel.nist.gov> > From: Michael McLay > To: martin@tchibm3.chemie.uni-karlsruhe.de (MARTIN GEGENHEIMER AK kappes) > Subject: [PYTHON MATRIX-SIG] [Q] Array->String conversion, how? > In-Reply-To: <9605230818.AA26109@ipc2ibm1.chemie.uni-karlsruhe.de> > References: <9605230818.AA26109@ipc2ibm1.chemie.uni-karlsruhe.de> > > MARTIN GEGENHEIMER AK writes: > > Hello, > > > > I think I need som help: > > > > I'd like to convert a numeric array to a string like > > (to pass it to Tcl) > > > > { 1.0 2.0 .... } > > > > I tried : > > > > str(), repr(), but that gives me : > > "array([0,1,2,3,4,5,6,7,8,9], 'l')" > > > > a.toList() is much more what I want (its also fast for larger arrays) > > > > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > > but I don't want ',' or braces. > > > > a.toString() > > does no do what I want. > > > > > > so, how ? > > > > maybe make a modified toList() ? > > > How about using a.toList() to produce > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > > and then do a gsub to replace ", " with " ". > I wanted to do that when everything else fails. :-( - Martin -- Martin Gegenheimer Institut fuer Physikalische Chemie II Kaiserstr.12 76128 Karlsruhe Germany home-page: http://www.chemie.uni-karlsruhe.de/~martin e-mail: martin@ipc2ibm1.chemie.uni-karlsruhe.de voice: ++49 721 608-3255 fax : ++49 721 608-3310 ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From da@maigret.cog.brown.edu Thu May 23 14:12:52 1996 From: da@maigret.cog.brown.edu (David Ascher) Date: Thu, 23 May 1996 09:12:52 -0400 (EDT) Subject: [PYTHON MATRIX-SIG] [Q] Array->String conversion, how? In-Reply-To: <9605230818.AA26109@ipc2ibm1.chemie.uni-karlsruhe.de> from "MARTIN GEGENHEIMER AK kappes" at May 23, 96 10:18:39 am Message-ID: <199605231312.JAA18508@maigret> Well, this might be a place to start: a = arange(10) string.join(map(str, a)) '0 1 2 3 4 5 6 7 8 9' a = arange(0.0,10.0) string.join(map(str, a)) '0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0' Speaking of which, isn't it odd that: >>> arange(10) 0 1 2 3 4 5 6 7 8 9 >>> arange(10.0) 0 1 2 3 4 5 6 7 8 9 >>> arange(0.0,10.0) 0.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From guido@CNRI.Reston.Va.US Thu May 23 15:53:53 1996 From: guido@CNRI.Reston.Va.US (Guido van Rossum) Date: Thu, 23 May 1996 10:53:53 -0400 Subject: [PYTHON MATRIX-SIG] [Q] Array->String conversion, how? In-Reply-To: Your message of "Thu, 23 May 1996 13:51:45 +0200." <9605231151.AA05001@ipc2ibm1.chemie.uni-karlsruhe.de> References: <9605231151.AA05001@ipc2ibm1.chemie.uni-karlsruhe.de> Message-ID: <199605231453.KAA25393@monty> > > How about using a.toList() to produce > > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > > > > and then do a gsub to replace ", " with " ". Or this: "{%s}" % string.join(map(str, a)) --Guido van Rossum (home page: http://www.python.org/~guido/) ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From pas@lems.brown.edu Fri May 24 17:10:14 1996 From: pas@lems.brown.edu (Perry A. Stoll) Date: Fri, 24 May 1996 12:10:14 -0400 (EDT) Subject: [PYTHON MATRIX-SIG] having problems (in arange)? In-Reply-To: <199605231312.JAA18508@maigret> Message-ID: Did everyone remember to remove the old .pyc files for Numeric? I did that only when I couldn't find 'index_expression' when I imported Numeric and all sorts of problems went away. I get the following: >>> arange(10) 0 1 2 3 4 5 6 7 8 9 >>> arange(10.0) 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. -Perry On Thu, 23 May 1996, David Ascher wrote: > Speaking of which, isn't it odd that: > > >>> arange(10) > 0 1 2 3 4 5 6 7 8 9 > >>> arange(10.0) > 0 1 2 3 4 5 6 7 8 9 > >>> arange(0.0,10.0) > 0.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 > ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From guido@CNRI.Reston.Va.US Fri May 24 21:59:13 1996 From: guido@CNRI.Reston.Va.US (Guido van Rossum) Date: Fri, 24 May 1996 16:59:13 -0400 Subject: [PYTHON MATRIX-SIG] what to do with public symbols c_* Message-ID: <199605242059.QAA07559@monty> I'm trying to make Python 1.4 "clean" with respect to exporting symbols: all exported symbols except for init will have a Py or _Py prefix. There are a bunch of symbols defined in complexobject.c and cmathmodule.c whose name begin with "c_", for instance c_sum() and c_sin(). If I rename the ones defined in complexoject.h (c_sum, c_diff, c_neg, c_prod, c_quot and c_pow) and make the ones in cmathmodule.c static, would this break any code in the matrix extensions? --Guido van Rossum (home page: http://www.python.org/~guido/) ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From jjh@goldilocks.lcs.mit.edu Fri May 24 22:45:20 1996 From: jjh@goldilocks.lcs.mit.edu (James Hugunin) Date: Fri, 24 May 1996 17:45:20 -0400 Subject: [PYTHON MATRIX-SIG] what to do with public symbols c_* In-Reply-To: <199605242059.QAA07559@monty> (message from Guido van Rossum on Fri, 24 May 1996 16:59:13 -0400) Message-ID: <199605242145.RAA00282@ling-ling.zoo> From: Guido van Rossum I'm trying to make Python 1.4 "clean" with respect to exporting symbols: all exported symbols except for init will have a Py or _Py prefix. There are a bunch of symbols defined in complexobject.c and cmathmodule.c whose name begin with "c_", for instance c_sum() and c_sin(). If I rename the ones defined in complexoject.h (c_sum, c_diff, c_neg, c_prod, c_quot and c_pow) and make the ones in cmathmodule.c static, would this break any code in the matrix extensions? --Guido van Rossum (home page: http://www.python.org/~guido/) This won't cause any problems with the matrix extension. These functions are defined statically in the array math code (twice actually, but that's too embarrassing to explain here). This is a hold over from when it wasn't guaranteed that complex numbers would be part of the python core. After the release of 1.4, I'll probably remove the static definitions and use the Py prefixed versions instead. -Jim ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From jjh@goldilocks.lcs.mit.edu Fri May 24 22:45:20 1996 From: jjh@goldilocks.lcs.mit.edu (James Hugunin) Date: Fri, 24 May 1996 17:45:20 -0400 Subject: [PYTHON MATRIX-SIG] what to do with public symbols c_* In-Reply-To: <199605242059.QAA07559@monty> (message from Guido van Rossum on Fri, 24 May 1996 16:59:13 -0400) Message-ID: <199605242145.RAA00282@ling-ling.zoo> From: Guido van Rossum I'm trying to make Python 1.4 "clean" with respect to exporting symbols: all exported symbols except for init will have a Py or _Py prefix. There are a bunch of symbols defined in complexobject.c and cmathmodule.c whose name begin with "c_", for instance c_sum() and c_sin(). If I rename the ones defined in complexoject.h (c_sum, c_diff, c_neg, c_prod, c_quot and c_pow) and make the ones in cmathmodule.c static, would this break any code in the matrix extensions? --Guido van Rossum (home page: http://www.python.org/~guido/) This won't cause any problems with the matrix extension. These functions are defined statically in the array math code (twice actually, but that's too embarrassing to explain here). This is a hold over from when it wasn't guaranteed that complex numbers would be part of the python core. After the release of 1.4, I'll probably remove the static definitions and use the Py prefixed versions instead. -Jim ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From hinsenk@ere.umontreal.ca Tue May 28 00:51:37 1996 From: hinsenk@ere.umontreal.ca (Konrad HINSEN) Date: Mon, 27 May 1996 19:51:37 -0400 Subject: [PYTHON MATRIX-SIG] [Q] Array->String conversion, how? In-Reply-To: <199605231312.JAA18508@maigret> (da@maigret.cog.brown.edu) Message-ID: <199605272351.TAA22272@cyclone.ERE.UMontreal.CA> > Speaking of which, isn't it odd that: > > >>> arange(10) > 0 1 2 3 4 5 6 7 8 9 > >>> arange(10.0) > 0 1 2 3 4 5 6 7 8 9 > >>> arange(0.0,10.0) > 0.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 On my machine the last two give the same answer, as expected. If they don't for you, I suspect rounding problems. Check if arange(0.0,10.0)-arange(10.0) really gives zeroes. If so, my printing code behaves funnily on your machine. If not, arange() behaves funnily ;-) ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsenk@ere.umontreal.ca Departement de chimie | Tel.: +1-514-343-6111 ext. 3953 Universite de Montreal | Fax: +1-514-343-7586 C.P. 6128, succ. Centre-Ville | Deutsch/Esperanto/English/Nederlands/ Montreal (QC) H3C 3J7 | Francais (phase experimentale) ------------------------------------------------------------------------------- ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From hinsenk@ere.umontreal.ca Tue May 28 00:51:37 1996 From: hinsenk@ere.umontreal.ca (Konrad HINSEN) Date: Mon, 27 May 1996 19:51:37 -0400 Subject: [PYTHON MATRIX-SIG] [Q] Array->String conversion, how? In-Reply-To: <199605231312.JAA18508@maigret> (da@maigret.cog.brown.edu) Message-ID: <199605272351.TAA22272@cyclone.ERE.UMontreal.CA> > Speaking of which, isn't it odd that: > > >>> arange(10) > 0 1 2 3 4 5 6 7 8 9 > >>> arange(10.0) > 0 1 2 3 4 5 6 7 8 9 > >>> arange(0.0,10.0) > 0.00000 1.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 On my machine the last two give the same answer, as expected. If they don't for you, I suspect rounding problems. Check if arange(0.0,10.0)-arange(10.0) really gives zeroes. If so, my printing code behaves funnily on your machine. If not, arange() behaves funnily ;-) ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsenk@ere.umontreal.ca Departement de chimie | Tel.: +1-514-343-6111 ext. 3953 Universite de Montreal | Fax: +1-514-343-7586 C.P. 6128, succ. Centre-Ville | Deutsch/Esperanto/English/Nederlands/ Montreal (QC) H3C 3J7 | Francais (phase experimentale) ------------------------------------------------------------------------------- ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From busby@icf.llnl.gov Tue May 28 17:46:40 1996 From: busby@icf.llnl.gov (L. Busby) Date: Tue, 28 May 96 09:46:40 PDT Subject: [PYTHON MATRIX-SIG] ANNOUNCE: Gist Scientific graphics module for Python Message-ID: <9605281646.AA29432@icf.llnl.gov> I'm releasing the first version of my Gist module for Python. You can pick up a copy at ftp-icf.llnl.gov:/pub/python/busby/pygist-1.0.tgz This module is dependent on the Numeric module due to Hugunin and others. So until that module reaches public release, the Gist module should also stay within the matrix-sig. Following is the README.gist file from the release: ============================================================================== This is the README file for the Python Gist Scientific Graphics Module, version 1.0, written by Lee Busby of Lawrence Livermore National Laboratory. Copyright (c) 1996. The Regents of the University of California. All rights reserved. ============================================================================== DESCRIPTION "Gist" is a scientific graphics library written by David H. Munro of Lawrence Livermore National Laboratory. It features support for three common graphics output devices: X-Windows, (Color) PostScript, and ANSI/ISO Standard Computer Graphics Metafiles (CGM). The library is small (written directly to Xlib), portable, efficient, and full-featured. It produces x-vs-y plots with "good" tick marks and tick labels, 2-D quadrilateral mesh plots with contours, vector fields, or pseudocolor maps on such meshes, with 3-D plots on the way. The Python Gist module utilizes the new ``Numeric'' module due to J. Hugunin and others. It is therefore fast and able to handle large datasets. The Gist module includes an X-windows event dispatcher which can be dynamically added (e.g., via importing a dynamically loaded module) to the Python interpreter after a simple two-line modification to the Python core. This makes fast mouse-controlled zoom, pan, and other graphic operations available to the researcher while maintaining the usual Python command-line interface. ============================================================================== AVAILABILITY ftp-icf.llnl.gov:/pub/python/busby/pygist-1.0.tgz ============================================================================== CONTENTS OF THE PACKAGE ./LEGAL.gist : Copyright and Disclaimer ./Lib/numeric/gist.help : Major documentation for gist module ./Lib/numeric/gist.py : Python code for gist module ./Lib/numeric/gistdemo.py : Demonstration program ./Lib/numeric/help.help : Documentation for help module ./Lib/numeric/help.py : The help module ./Modules/Setup.forgist : Typical compilation lines for gist ./Modules/gistCmodule.c : C code for gist module ./Parser/myreadline.c : Replacement for python file ./README.gist : This file ============================================================================== INSTALLATION Installation of the Python gist module is complicated by its dependence on another not-yet standard Python module, the "Numeric" module by Hugunin et al, and the Gist graphics library itself. The Gist module has been tested only with Python 1.3. The current version of the Numeric module as of 24May96 can be obtained as ftp://sls-ftp.lcs.mit.edu/pub/jjh/NumericalPython-0.36.tar.gz It includes instructions sufficient for its installation. The Gist library is included with the distribution of David Munro's Yorick interpreter. The current version is 1.2. Yorick can be obtained at ftp-icf.llnl.gov:/pub/Yorick/yorick-1.2.tar.gz wuarchive.wustl.edu: /languages/yorick/yorick-1.2.tar.gz sunsite.unc.edu: /pub/languages/yorick/yorick-1.2.tar.gz sunsite.unc.edu: /pub/Linux/apps/math/matrix/yorick-1.2.tar.gz netlib.att.com: /netlib/env/yorick-1.2.tar.gz netlib2.cs.utk.edu: /env/yorick-1.2.tar.gz Yorick also includes ample instructions for its installation. It is easiest to simply install the entire Yorick distribution. This requires only about 5MB of disk space. Building Yorick requires 10-15MB of additional temporary space. If you are interested in Python Gist, chances are you may also be interested in Yorick itself. However, should you desire to remove the files not strictly necessary for compilation and installation of Python Gist, here is a list of the *required* files and directories: (${prefix} defaults to /usr/local.) ${prefix}/Yorick/gist # Style and color palette files ${prefix}/bin/gist # Standalone CGM browser program ${prefix}/lib/libgist.a # The Gist library ${prefix}/yorhome/{dispas.h, dispat.h, gist.h, hlevel.h} # header files You may also want to save or print out various documentation files included with Yorick. After you have installed Yorick and unpacked the Numeric module into your toplevel Python working directory, you are ready to install Gist: CONCISE INSTRUCTIONS 1) Install Yorick. 2) Untar the Numeric module into your toplevel Python working directory, and follow its instructions up to the point where you would begin compilation of python. (Untar the additional patches and make necessary additions and modifications to Modules/Setup.) 3) Copy pygist-1.0.tgz to the top of your python distribution. 4) cd Python-1.3; zcat pygist-1.0.tgz | tar xf - This adds files at the top level, and in subdirectories Lib and Modules. It overwrites the file Parser/myreadline.c with a slightly modified version. Save a backup copy if you want to compare the change. 5) Modify Modules/Setup by adding appropriate lines from Modules/Setup.forgist. Setup.forgist assumes that you installed Yorick in its default location. Change YPREFIX as necessary if your Yorick is installed somewhere else. The gist module can be dynamically loaded on most platforms, if you prefer. 6) Configure and compile Python. ============================================================================= RUNNING GIST After you have successfully compiled Python with Gist, you can test it by running >>> import gistdemo >>> gistdemo.run() and you can get started with the online help using >>> from gist import * >>> help("help.") >>> help("gist.") ============================================================================= AUTHOR'S ADDRESS Lee Busby, mailstop L-472 Lawrence Livermore National Laboratory 7000 East Avenue Livermore, CA, USA 94550 E-mail: busby1@llnl.gov ============================================================================= ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From busby@icf.llnl.gov Tue May 28 17:46:40 1996 From: busby@icf.llnl.gov (L. Busby) Date: Tue, 28 May 96 09:46:40 PDT Subject: [PYTHON MATRIX-SIG] ANNOUNCE: Gist Scientific graphics module for Python Message-ID: <9605281646.AA29432@icf.llnl.gov> I'm releasing the first version of my Gist module for Python. You can pick up a copy at ftp-icf.llnl.gov:/pub/python/busby/pygist-1.0.tgz This module is dependent on the Numeric module due to Hugunin and others. So until that module reaches public release, the Gist module should also stay within the matrix-sig. Following is the README.gist file from the release: ============================================================================== This is the README file for the Python Gist Scientific Graphics Module, version 1.0, written by Lee Busby of Lawrence Livermore National Laboratory. Copyright (c) 1996. The Regents of the University of California. All rights reserved. ============================================================================== DESCRIPTION "Gist" is a scientific graphics library written by David H. Munro of Lawrence Livermore National Laboratory. It features support for three common graphics output devices: X-Windows, (Color) PostScript, and ANSI/ISO Standard Computer Graphics Metafiles (CGM). The library is small (written directly to Xlib), portable, efficient, and full-featured. It produces x-vs-y plots with "good" tick marks and tick labels, 2-D quadrilateral mesh plots with contours, vector fields, or pseudocolor maps on such meshes, with 3-D plots on the way. The Python Gist module utilizes the new ``Numeric'' module due to J. Hugunin and others. It is therefore fast and able to handle large datasets. The Gist module includes an X-windows event dispatcher which can be dynamically added (e.g., via importing a dynamically loaded module) to the Python interpreter after a simple two-line modification to the Python core. This makes fast mouse-controlled zoom, pan, and other graphic operations available to the researcher while maintaining the usual Python command-line interface. ============================================================================== AVAILABILITY ftp-icf.llnl.gov:/pub/python/busby/pygist-1.0.tgz ============================================================================== CONTENTS OF THE PACKAGE ./LEGAL.gist : Copyright and Disclaimer ./Lib/numeric/gist.help : Major documentation for gist module ./Lib/numeric/gist.py : Python code for gist module ./Lib/numeric/gistdemo.py : Demonstration program ./Lib/numeric/help.help : Documentation for help module ./Lib/numeric/help.py : The help module ./Modules/Setup.forgist : Typical compilation lines for gist ./Modules/gistCmodule.c : C code for gist module ./Parser/myreadline.c : Replacement for python file ./README.gist : This file ============================================================================== INSTALLATION Installation of the Python gist module is complicated by its dependence on another not-yet standard Python module, the "Numeric" module by Hugunin et al, and the Gist graphics library itself. The Gist module has been tested only with Python 1.3. The current version of the Numeric module as of 24May96 can be obtained as ftp://sls-ftp.lcs.mit.edu/pub/jjh/NumericalPython-0.36.tar.gz It includes instructions sufficient for its installation. The Gist library is included with the distribution of David Munro's Yorick interpreter. The current version is 1.2. Yorick can be obtained at ftp-icf.llnl.gov:/pub/Yorick/yorick-1.2.tar.gz wuarchive.wustl.edu: /languages/yorick/yorick-1.2.tar.gz sunsite.unc.edu: /pub/languages/yorick/yorick-1.2.tar.gz sunsite.unc.edu: /pub/Linux/apps/math/matrix/yorick-1.2.tar.gz netlib.att.com: /netlib/env/yorick-1.2.tar.gz netlib2.cs.utk.edu: /env/yorick-1.2.tar.gz Yorick also includes ample instructions for its installation. It is easiest to simply install the entire Yorick distribution. This requires only about 5MB of disk space. Building Yorick requires 10-15MB of additional temporary space. If you are interested in Python Gist, chances are you may also be interested in Yorick itself. However, should you desire to remove the files not strictly necessary for compilation and installation of Python Gist, here is a list of the *required* files and directories: (${prefix} defaults to /usr/local.) ${prefix}/Yorick/gist # Style and color palette files ${prefix}/bin/gist # Standalone CGM browser program ${prefix}/lib/libgist.a # The Gist library ${prefix}/yorhome/{dispas.h, dispat.h, gist.h, hlevel.h} # header files You may also want to save or print out various documentation files included with Yorick. After you have installed Yorick and unpacked the Numeric module into your toplevel Python working directory, you are ready to install Gist: CONCISE INSTRUCTIONS 1) Install Yorick. 2) Untar the Numeric module into your toplevel Python working directory, and follow its instructions up to the point where you would begin compilation of python. (Untar the additional patches and make necessary additions and modifications to Modules/Setup.) 3) Copy pygist-1.0.tgz to the top of your python distribution. 4) cd Python-1.3; zcat pygist-1.0.tgz | tar xf - This adds files at the top level, and in subdirectories Lib and Modules. It overwrites the file Parser/myreadline.c with a slightly modified version. Save a backup copy if you want to compare the change. 5) Modify Modules/Setup by adding appropriate lines from Modules/Setup.forgist. Setup.forgist assumes that you installed Yorick in its default location. Change YPREFIX as necessary if your Yorick is installed somewhere else. The gist module can be dynamically loaded on most platforms, if you prefer. 6) Configure and compile Python. ============================================================================= RUNNING GIST After you have successfully compiled Python with Gist, you can test it by running >>> import gistdemo >>> gistdemo.run() and you can get started with the online help using >>> from gist import * >>> help("help.") >>> help("gist.") ============================================================================= AUTHOR'S ADDRESS Lee Busby, mailstop L-472 Lawrence Livermore National Laboratory 7000 East Avenue Livermore, CA, USA 94550 E-mail: busby1@llnl.gov ============================================================================= ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From Emmanuel.Viennet@laforia.ibp.fr Wed May 29 18:40:31 1996 From: Emmanuel.Viennet@laforia.ibp.fr (VIENNET Emmanuel 48.06.27.97 Equipe Gallinari) Date: Wed, 29 May 1996 19:40:31 +0200 Subject: [PYTHON MATRIX-SIG] Two questions Message-ID: <199605291740.TAA26065@lpia2.ibp.fr> Hi all, I'm using Numerical Python 0.36 since a few weeks and I'm really impressed... Two questions, however: 1- I'd like to compute with floats, instead of doubles, to save storage (for now, I frequently run out of my 100Mo swap space). 1.1 : this is probably a bug: >>> from Numeric import * >>> a = ones(10,Float(32)) >>> a.typecode() 'd' 1.2 : the above bug comes from an implicit conversion : >>> a = zeros(10,Float(32)) >>> a.typecode() 'f' >>> b = a + 1 >>> b.typecode() 'd' The consequence is that's currently impossible to compute with floats... ? I don't exactly remember the conclusions from the previous discussions about conversion rules, but the current behaviour is uncomfortable, especially with *big* arrays. Did I miss something ? 2- The second question : The following code builds and returns an array from C: PyArrayObject arr = (PyArrayObject *)PyArray_FromDims( nbdims,dims, PyArray_FLOAT ); if (!arr) { ... } do something with arr->data return Py_BuildValue("O", arr ); Is this right ? (This seems to leak). Thanks for your attention Emmanuel -- Emmanuel Viennet: LIPN - Institut Galilee - Universite Paris-Nord 93430 Villetaneuse - France ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From dubois1@llnl.gov Wed May 29 19:00:21 1996 From: dubois1@llnl.gov (Paul F. Dubois) Date: Wed, 29 May 96 11:00:21 PDT Subject: [PYTHON MATRIX-SIG] Two questions Message-ID: <9605291800.AA15205@icf.llnl.gov> We decided to make it harder to compute with floats rather than hard to behave normally. (:->. Seriously, the design tradeoff was to either force the person who wanted to be sure they stayed float to be more careful or to screw up automatic type conversion. Since double does not cost a great deal more CPU than single, the issue is just those arrays for which space is a major issue. In your example you need to make the scalar you are adding to 'a' to also be a float array of size 1. Yes, your example leaks. Just return the new array without Py_BuildValue, since the latter adds a reference. You already have one from the creation call. > > Hi all, > >I'm using Numerical Python 0.36 since a few weeks and I'm really >impressed... >Two questions, however: > > 1- I'd like to compute with floats, instead of doubles, to save > storage (for now, I frequently run out of my 100Mo swap space). > 1.1 : this is probably a bug: > >>> from Numeric import * > >>> a = ones(10,Float(32)) > >>> a.typecode() > 'd' > 1.2 : the above bug comes from an implicit conversion : > >>> a = zeros(10,Float(32)) > >>> a.typecode() > 'f' > >>> b = a + 1 > >>> b.typecode() > 'd' >The consequence is that's currently impossible to compute with >floats... ? I don't exactly remember the conclusions from the >previous discussions about conversion rules, but the current behaviour >is uncomfortable, especially with *big* arrays. Did I miss something ? > > > 2- The second question : >The following code builds and returns an array from C: > > PyArrayObject arr = (PyArrayObject *)PyArray_FromDims( > nbdims,dims, PyArray_FLOAT ); > if (!arr) { > ... > } > do something with arr->data > > return Py_BuildValue("O", arr ); > >Is this right ? (This seems to leak). > > >Thanks for your attention >Emmanuel > >-- >Emmanuel Viennet: >LIPN - Institut Galilee - Universite Paris-Nord >93430 Villetaneuse - France > >================= >MATRIX-SIG - SIG on Matrix Math for Python > >send messages to: matrix-sig@python.org >administrivia to: matrix-sig-request@python.org >================= > > Paul F. Dubois Lawrence Livermore National Laboratory ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From pas@lems.brown.edu Wed May 29 19:16:46 1996 From: pas@lems.brown.edu (Perry A. Stoll) Date: Wed, 29 May 1996 14:16:46 -0400 (EDT) Subject: [PYTHON MATRIX-SIG] Two questions In-Reply-To: <199605291740.TAA26065@lpia2.ibp.fr> Message-ID: On Wed, 29 May 1996, VIENNET Emmanuel 48.06.27.97 Equipe Gallinari wrote: > > Hi all, > > I'm using Numerical Python 0.36 since a few weeks and I'm really great! > > 1- I'd like to compute with floats, instead of doubles, to save Nasty matte, that. I'll wait for more knowledgable folks to answer that... > 2- The second question : > The following code builds and returns an array from C: > > PyArrayObject arr = (PyArrayObject *)PyArray_FromDims( > nbdims,dims, PyArray_FLOAT ); [snip]> > return Py_BuildValue("O", arr ); > Is this right ? (This seems to leak). That's a leak. In this case all you need to do: return (PyObject *)arr; When you create an object, in this case with the function PyArra_FromDims, you almost always own a reference to it. All you need to do is pass "your" reference back to the interpreter. Using Py_BuildValue, you're creating an extra reference to "arr" which never gets deleted and leaks memory. --Perry ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From pas@lems.brown.edu Wed May 29 19:16:46 1996 From: pas@lems.brown.edu (Perry A. Stoll) Date: Wed, 29 May 1996 14:16:46 -0400 (EDT) Subject: [PYTHON MATRIX-SIG] Two questions In-Reply-To: <199605291740.TAA26065@lpia2.ibp.fr> Message-ID: On Wed, 29 May 1996, VIENNET Emmanuel 48.06.27.97 Equipe Gallinari wrote: > > Hi all, > > I'm using Numerical Python 0.36 since a few weeks and I'm really great! > > 1- I'd like to compute with floats, instead of doubles, to save Nasty matte, that. I'll wait for more knowledgable folks to answer that... > 2- The second question : > The following code builds and returns an array from C: > > PyArrayObject arr = (PyArrayObject *)PyArray_FromDims( > nbdims,dims, PyArray_FLOAT ); [snip]> > return Py_BuildValue("O", arr ); > Is this right ? (This seems to leak). That's a leak. In this case all you need to do: return (PyObject *)arr; When you create an object, in this case with the function PyArra_FromDims, you almost always own a reference to it. All you need to do is pass "your" reference back to the interpreter. Using Py_BuildValue, you're creating an extra reference to "arr" which never gets deleted and leaks memory. --Perry ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From barton@simsg1.mdc.com Wed May 29 23:40:05 1996 From: barton@simsg1.mdc.com (Brien Barton) Date: Wed, 29 May 1996 15:40:05 -0700 (PDT) Subject: [PYTHON MATRIX-SIG] Numerical exception handling Message-ID: My apologies if this has already been covered. The following is a demonstration of an error that is not handled gracefully when using array objects: >>> b=array([1,2,3]) >>> b.x=10 Fatal Python error: print_error called but no exception Abort (core dumped) Other objects, such as an integer variable, don't cause a core dump: >>> a=5 >>> a.x=10 Traceback (innermost last): File "", line 1, in ? TypeError: attribute-less object (assign or del) =============================================================================== Brien Barton McDonnell Douglas Aerospace, Huntington Beach, CA email: barton@simsg1.mdc.com, voice: (714)896-2249, fax:(714)896-5939 ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org =================