From hinsen@ibs.ibs.fr Sun Feb 2 14:40:22 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Sun, 2 Feb 1997 15:40:22 +0100 Subject: [PYTHON MATRIX-SIG] mean, add.reduce, and MLab.py In-Reply-To: <01BC0F7F.2698C2A0@misha.lcs.mit.edu> (message from Jim Hugunin on Fri, 31 Jan 1997 14:00:43 -0500) Message-ID: <199702021440.PAA29259@lmspc2.ibs.fr> > 2) I don't understand people's complaints about the mean function at all. > In fact, getting this to work right for multi-dimensional arrays was one > of the plethora of reasons that reduce uses axis 0 by default. > > Could someone give me an example of how "x - add.reduce(x)/len(x)" doesn't > work as expected? I'd argue that if this isn't the result you're looking > for, then you don't quite understand NumPy's model of an array (I could be > wrong...) I agree to some degree. If you find that it systematically something else than you expect, you have probably not chosen the right Python representation for your data objects. But of course there are occasions when explicit axis specifications are necessary - otherwise they wouldn't be possible! -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen@ibs.ibs.fr Laboratoire de Dynamique Moleculaire | Tel.: +33-4.76.88.99.28 Institut de Biologie Structurale | Fax: +33-4.76.88.54.94 41, av. des Martyrs | Deutsch/Esperanto/English/ 38027 Grenoble Cedex 1, France | Nederlands/Francais ------------------------------------------------------------------------------- _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From hinsen@ibs.ibs.fr Tue Feb 4 18:49:35 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Tue, 4 Feb 1997 19:49:35 +0100 Subject: [PYTHON MATRIX-SIG] netCDF module Message-ID: <199702041849.TAA06352@lmspc2.ibs.fr> I'd just like to remind all users of my netCDF module that there have been quite a few changes recently (i.e. bug fixes), so it's worth getting a new copy if you haven't done so recently. The URL is still http://www.yi.com/home/HinsenKonrad/netcdf.html Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen@ibs.ibs.fr Laboratoire de Dynamique Moleculaire | Tel.: +33-4.76.88.99.28 Institut de Biologie Structurale | Fax: +33-4.76.88.54.94 41, av. des Martyrs | Deutsch/Esperanto/English/ 38027 Grenoble Cedex 1, France | Nederlands/Francais ------------------------------------------------------------------------------- _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From Dale_Bertrand@brown.edu Thu Feb 6 13:50:41 1997 From: Dale_Bertrand@brown.edu (Dale Bertrand) Date: Thu, 06 Feb 1997 08:50:41 -0500 Subject: [PYTHON MATRIX-SIG] Numeric typecodes Message-ID: <199702061350.IAA14466@golden.brown.edu> I'm using a pre 1.0 version of Numeric which does seem to support all the typecodes in v1.0. For the available types for Floats are 'd' and 'f'. Would someone please tell me how many bytes these use to represent floating point data? -Dale --- Dale Bertrand -------- email: dale_bertrand@brown.edu quote: "I dislike forwards and silly quotes" _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From hinsen@ibs.ibs.fr Thu Feb 6 14:41:15 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Thu, 6 Feb 1997 15:41:15 +0100 Subject: [PYTHON MATRIX-SIG] Numeric typecodes In-Reply-To: <199702061350.IAA14466@golden.brown.edu> (message from Dale Bertrand on Thu, 06 Feb 1997 08:50:41 -0500) Message-ID: <199702061441.PAA15196@lmspc2.ibs.fr> > I'm using a pre 1.0 version of Numeric which does seem to support all the > typecodes in v1.0. For the available types for Floats are 'd' and 'f'. > Would someone please tell me how many bytes these use to represent floating > point data? That depends on your C compiler. 'd' stands for C 'double' (i.e. standard Python float precision), and 'f' stands for C 'float'. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen@ibs.ibs.fr Laboratoire de Dynamique Moleculaire | Tel.: +33-4.76.88.99.28 Institut de Biologie Structurale | Fax: +33-4.76.88.54.94 41, av. des Martyrs | Deutsch/Esperanto/English/ 38027 Grenoble Cedex 1, France | Nederlands/Francais ------------------------------------------------------------------------------- _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From x-aes@telelogic.se Fri Feb 7 09:21:53 1997 From: x-aes@telelogic.se (Andy Eskilsson) Date: 07 Feb 1997 10:21:53 +0100 Subject: [PYTHON MATRIX-SIG] NumPy on dos.. Message-ID: Just thought I should drop a line and say that I successfully compiled and integrated the NumPy module into python 1.4 for dos, with the help of djgpp, (D. J. Delories gcc port). There were one quirk, the compiler died if I tried to compile the zlapack_lite.c file with -O2 optimizations, but when I switched down to -O it compiled fine. Otherwise it worked smooth, I had just to follow the instructions (well I couldn't do that with a symbolic link, so I copied the files instead) and make.. (uhm well I have bash for dos, so I let configure do the makefiles for me.) /Andy p.s. I am not on this list, just thought you might be interested. _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From Dale_Bertrand@brown.edu Sat Feb 8 01:14:56 1997 From: Dale_Bertrand@brown.edu (Dale Bertrand) Date: Fri, 07 Feb 1997 20:14:56 -0500 Subject: [PYTHON MATRIX-SIG] Numeric typecodes Message-ID: <199702080114.UAA01999@golden.brown.edu> >> I'm using a pre 1.0 version of Numeric which does seem to support all the >> typecodes in v1.0. For the available types for Floats are 'd' and 'f'. >> Would someone please tell me how many bytes these use to represent floating >> point data? > >Same as the underlying data they represent, i.e. for a float, 'f', on a >sparc (which you're on ;) i believe it's 4 bytes. A double, 'd', is 8 >bytes. Since I can't throw 2 byte Float into an array, thinking about manipulating the two bytes into a 4 byte float by adding two bytes in the right places for each value. Will this work? I've made a diagram below. ** ** ** ** 2 byte float ** ** | | | --- | | ** ** ** ** ** ** ** ** 4 byte float ** ** ** ** ^ ^ | | (added zero bytes) --- Dale Bertrand -------- email: dale_bertrand@brown.edu quote: "I dislike forwards and silly quotes" _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From szummer@media.mit.edu Wed Feb 19 03:17:52 1997 From: szummer@media.mit.edu (Martin Szummer) Date: Tue, 18 Feb 1997 22:17:52 -0500 Subject: [PYTHON MATRIX-SIG] 2D slices of 1D array Message-ID: <9702190317.AA05985@arsenal.media.mit.edu> The following slice of a 1D array surprised me: >>> c = array([1,2,3,4,5]) >>> c 1 2 3 4 5 >>> c[1:3, :] EmptyArray I was expecting either 1,2,3 or an error. Is there any rational for this? The behavior is the same for higher dimensional arrays as well. (This is using Numeric 1.06a and Python 1.4) -- Martin Szummer MIT _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From hinsen@ibs.ibs.fr Wed Feb 19 09:03:02 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Wed, 19 Feb 1997 10:03:02 +0100 Subject: [PYTHON MATRIX-SIG] 2D slices of 1D array In-Reply-To: <9702190317.AA05985@arsenal.media.mit.edu> (message from Martin Szummer on Tue, 18 Feb 1997 22:17:52 -0500) Message-ID: <199702190903.KAA00286@lmspc2.ibs.fr> > The following slice of a 1D array surprised me: > > >>> c = array([1,2,3,4,5]) > >>> c > 1 2 3 4 5 > >>> c[1:3, :] > EmptyArray > > I was expecting either 1,2,3 or an error. > Is there any rational for this? None that I can think of. This ought to be an error. Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen@ibs.ibs.fr Laboratoire de Dynamique Moleculaire | Tel.: +33-4.76.88.99.28 Institut de Biologie Structurale | Fax: +33-4.76.88.54.94 41, av. des Martyrs | Deutsch/Esperanto/English/ 38027 Grenoble Cedex 1, France | Nederlands/Francais ------------------------------------------------------------------------------- _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From hugunin@mit.edu Thu Feb 20 00:08:38 1997 From: hugunin@mit.edu (Jim Hugunin) Date: Wed, 19 Feb 1997 19:08:38 -0500 Subject: [PYTHON MATRIX-SIG] 2D slices of 1D array Message-ID: <01BC1E98.50DE75F0@misha.lcs.mit.edu> This will now raise an IndexError exception as it should have all along. Thanks for the bug - Jim -----Original Message----- From: Konrad Hinsen [SMTP:hinsen@ibs.ibs.fr] > The following slice of a 1D array surprised me: > > >>> c = array([1,2,3,4,5]) > >>> c > 1 2 3 4 5 > >>> c[1:3, :] > EmptyArray > > I was expecting either 1,2,3 or an error. > Is there any rational for this? None that I can think of. This ought to be an error. Konrad. _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From djc@lct.com Fri Feb 21 17:23:20 1997 From: djc@lct.com (Duncan Child) Date: Fri, 21 Feb 97 11:23:20 CST Subject: [PYTHON MATRIX-SIG] Numerical Recipes Book Message-ID: <9702211723.AA28149@ lct.com> Hi all, Have the Press et al algorithms been hooked up yet? I just want to test a quick correlation thing this morning and it would be perfect if a 'NumRec' module was already available. I also have a large amount of my own algorithms that might need to be put into new modules so I would be interested to see how a large extension like the Numerical Recipes algorithms would be structured. Thanks a lot, Duncan _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From hinsen@ibs.ibs.fr Fri Feb 21 17:47:18 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Fri, 21 Feb 1997 18:47:18 +0100 Subject: [PYTHON MATRIX-SIG] Numerical Recipes Book In-Reply-To: <9702211723.AA28149@ lct.com> (djc@lct.com) Message-ID: <199702211747.SAA10832@lmspc2.ibs.fr> > Have the Press et al algorithms been hooked up yet? As far as I know no. > I just want to test a quick correlation thing this morning and > it would be perfect if a 'NumRec' module was already available. I don't know what you exactly you need, but perhaps the fft stuff that comes with NumPy is sufficient for calculating your correlations. > I also have a large amount of my own algorithms that might need > to be put into new modules so I would be interested to see how > a large extension like the Numerical Recipes algorithms would > be structured. Look at the wrappers for LAPACK etc. as an example. Also check out SWIG, there's a pointer to it on the Python Web site. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen@ibs.ibs.fr Laboratoire de Dynamique Moleculaire | Tel.: +33-4.76.88.99.28 Institut de Biologie Structurale | Fax: +33-4.76.88.54.94 41, av. des Martyrs | Deutsch/Esperanto/English/ 38027 Grenoble Cedex 1, France | Nederlands/Francais ------------------------------------------------------------------------------- _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From hohn@math.utah.edu Fri Feb 21 17:52:10 1997 From: hohn@math.utah.edu (Michael Hohn) Date: Fri, 21 Feb 1997 10:52:10 -0700 (MST) Subject: [PYTHON MATRIX-SIG] Numerical Recipes Book In-Reply-To: <9702211723.AA28149@ lct.com> (djc@lct.com) Message-ID: <199702211752.KAA17439@alab06.math.utah.edu> >> ... >> >> Date: Fri, 21 Feb 97 11:23:20 CST >> From: djc@lct.com (Duncan Child) >> Sender: owner-matrix-sig@python.org >> Precedence: bulk >> >> >> Hi all, >> >> Have the Press et al algorithms been hooked up yet? >> >> ... A warning about Numerical Recipies may be in order. For a summary of why NOT to use this software, have a look at http://math.jpl.nasa.gov/nr/nr.html The netlib repository also has freely available software, and it's usually much higher quality. See http://www.netlib.org Cheers, Mike _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From hugunin@mit.edu Fri Feb 21 20:02:41 1997 From: hugunin@mit.edu (Jim Hugunin) Date: Fri, 21 Feb 1997 15:02:41 -0500 Subject: [PYTHON MATRIX-SIG] Numeric Python Beta 1 Released! Message-ID: <01BC2008.4BF62120@misha.lcs.mit.edu> I kept saying it was going to happen any day now...today's that day. Check out http://www.sls.lcs.mit.edu/~jjh/numpy for the first beta release of NumPy. It includes a source distribution that will work under both windows and unix, and an easy to install binary for Win NT/95. Grab it, install it, and let me know what you think (feel free to comment on the web pages as well...). Incompatible changes from the a6 release: binarysearch has been renamed to searchsorted Things that still need work (and for which help is greatly appreciated!): MLab.py does not work in this release Unix installation instructions need work, more info for different OS's Bug fixes (all known bugs are squashed in this release...) David Ascher needs to update his tutorial ;-) Talk Jack Jansen into sharing his Macintosh port with me ;-) Extension modules need to be built Simple C extension example Please send all bug reports directly to me (hugunin@mit.edu) and any questions about the system to the matrix-sig. I fear that I've lost many of the comments sent to me over the last five months due to a period of immense disorganization in my life. I'm now much better set up to collect bug reports and feature suggestions, so if I haven't addressed your comments in this latest release, please send them to me again. As usual, enjoy! - Jim _______________ 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 Fri Feb 21 22:43:45 1997 From: da@maigret.cog.brown.edu (David Ascher) Date: Fri, 21 Feb 1997 17:43:45 -0500 (EST) Subject: [PYTHON MATRIX-SIG] Numeric Python Beta 1 Released! In-Reply-To: <01BC2008.4BF62120@misha.lcs.mit.edu> Message-ID: > Things that still need work (and for which help is greatly appreciated!): .. > David Ascher needs to update his tutorial ;-) I'll do that when I can, but it won't be for at least 10 days, as I'll be in the Bay Area job hunting starting Sunday. Folks should feel free to send me specific requests if they have any. I have a big mailbox. Job offers are also welcome... --da _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From szummer@media.mit.edu Sun Feb 23 01:33:18 1997 From: szummer@media.mit.edu (Martin Szummer) Date: Sat, 22 Feb 1997 20:33:18 -0500 Subject: [PYTHON MATRIX-SIG] Numeric benchmark suite? Message-ID: <9702230133.AA08394@arsenal.media.mit.edu> Hi, I noticed some speed discrepancies between Python on different platforms (with otherwise comparable CPUs). (This concerns 1.0a6 under Linux, HPUX, IRIX, and Alpha). I would like to do a more thorough speed test, so I was wondering if anybody has a good benchmark suite? Ideally the benchmark suite should break up the results for different operations, such as matrixmultiply, addition, FFT, and also measure different data types (Integer, float, double, complex), and matrix sizes. I suspect the speed discrepancies depend on the compiler (cc vs. gcc) and compilation options. Any recommendations for compilers/options? -- Martin _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From hinsen@ibs.ibs.fr Sun Feb 23 09:33:24 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Sun, 23 Feb 1997 10:33:24 +0100 Subject: [PYTHON MATRIX-SIG] Updated installation instructions for NumPy 1.0b1 In-Reply-To: <01BC2008.4BF62120@misha.lcs.mit.edu> (message from Jim Hugunin on Fri, 21 Feb 1997 15:02:41 -0500) Message-ID: <199702230933.KAA17488@lmspc2.ibs.fr> There are two ways to install the numeric extensions. **Built in python source tree 1) Get the source distribution to python and configure it. 2) In the top-level directory of the source tree, unpack NumPy > gunzip NumPy-1.0b1.tar.gz > tar -xvmf NumPy-1.0b1.tar . 2a) unpack NumPyLib in the same directory using the same steps. This is not necessary if you have the "real" numeric libraries, but in that case you will need to change the Setup script as described below. 3a) Edit Modules/Setup from the python distribution to add the following lines: #This must occur above *shared* if you are building dynamic extensions # Jim Hugunin's numeric python extensions #The core functionality of multidimensional arrays multiarray -I../NumPy/Include ../NumPy/multiarraymodule.c ../NumPy/arrayobject.c ../NumPy/ufuncobject.c #The rest of this can be built dynamically and occur below *shared* # NumPy path NUMPYPATH=:$(DESTLIB)/NumPy #The basic math functions (+,-,...,log,...,greater_equal) fast_umath -I../NumPy/Include ../NumPy/fast_umathmodule.c -lm umath -I../NumPy/Include ../NumPy/umathmodule.c -lm #If you have a real fftpack library, include it here. fftpack -I../NumPy/Include -I../NumPy/NumPyLib ../NumPy/fftpackmodule.c ../NumPy/NumPyLib/fftpack.c #Link with the real lapack library (and F77/I77/BLAS) if you have it lapack_lite -I../NumPy/Include -I../NumPy/NumPyLib ../NumPy/lapack_litemodule.c ../NumPy/NumPyLib/dlapack_lite.c ../NumPy/NumPyLib/zlapack_lite.c ../NumPy/NumPyLib/blas_lite.c ../NumPy/NumPyLib/f2c_lite.c #Link with the real ranlib if you have it ranlib -I../NumPy/Include -I../NumPy/NumPyLib ../NumPy/ranlibmodule.c ../NumPy/NumPyLib/ranlib.c ../NumPy/NumPyLib/com.c ../NumPy/NumPyLib/linpack.c 3b) Locate the line starting with COREPYTHONPATH= in Modules/Setup. Add "$(NUMPYPATH)" (without the quotes) at the end of this line 4) Edit the file Makefile.in in the top-level directory of the Python distribution. Locate the line starting with LIBSUBDIRS=. Add " NumPy" (without the quotes) at the end of this line. 5) Add a symbolic link to the Numeric python libraries (In the top level python directory) > cd Lib; ln -s ../NumPy/NumPy NumPy 6) Configure, build and install the python distribution (see the Python installation instructions for details): > configure > make install If you have already configured your Python distribution, it is not necessary to redo this step if you make the modification described in step 4) also to the file Makefile. You should, however, recompile everything and install the new Python binary, which will have a different default search path than the standard version: > make clean > make install **Built as a clean extension 1) Unpack NumPy anywhere 2) In NumPy, type: > make -f Makefile.pre.in Makefile > make 3) Add this NumPy directory to your PYTHONPATH environment variable. You should run the supplied test cases in order to see if things are working on your system: > cd NumPy/test > python test_all.py If you plan to install extensions (i.e. C modules) that need NumPy, note that they will have to include the file NumPy/Include/arrayobject.h. The best solution is to copy this file into the directory that contains the other Python include files (i.e. normally /usr/local/include/python1.4). Then you won't have to do anything special to compile other extensions later. Note that there is documentation (ugly but reasonably complete) in doc.html The distribution was created by executing the following: tar -cvf NumPy-1.0b1.tar NumPy/INSTALL NumPy/Makefile.pre.in NumPy/Setup NumPy/makefile_nt.msc NumPy/numpy_nt.def NumPy/numpy.mak NumPy/numpy.mdp NumPy/html/*.html NumPy/*.c NumPy/*.h NumPy/Include/* NumPy/NumPy/*.py NumPy/test/test_*.py NumPy/Demo/*.py NumPy/Misc/* tar -cvf NumPyLib-1.0b1.tar NumPy/NumPyLib/*.c NumPy/NumPyLib/*.h System specific notes: **HP/UX** Some of the code uses ANSI features and some of the code is standard C. This makes the HP compilier unhappy. There are two solutions: 1) Use Gnu's free "gcc" compilier 2) Use the following command sequence for compilation: make -k make OPT="-Ae -O" _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From hinsen@ibs.ibs.fr Sun Feb 23 09:33:43 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Sun, 23 Feb 1997 10:33:43 +0100 Subject: [PYTHON MATRIX-SIG] Fixed version of LinearAlgebra.py In-Reply-To: <01BC2008.4BF62120@misha.lcs.mit.edu> (message from Jim Hugunin on Fri, 21 Feb 1997 15:02:41 -0500) Message-ID: <199702230933.KAA17492@lmspc2.ibs.fr> # This module is a lite version of LinAlg.py module which contains # high-level Python interface to the LAPACK library. The lite version # only accesses the following LAPACK functions: dgesv, zgesv, dgeev, # zgeev, dgesvd, zdesvd, dgelss, zgelss. import Numeric import copy import lapack_lite # Error object LinAlgError = 'LinearAlgebraError' # Helper routines _lapack_type = {'f': 0, 'd': 1, 'F': 2, 'D': 3} _lapack_letter = ['s', 'd', 'c', 'z'] _array_kind = {'i':0, 'l': 0, 'f': 0, 'd': 0, 'F': 1, 'D': 1} _array_precision = {'i': 1, 'l': 1, 'f': 0, 'd': 1, 'F': 0, 'D': 1} _array_type = [['f', 'd'], ['F', 'D']] def _commonType(*arrays): kind = 0 # precision = 0 # force higher precision in lite version precision = 1 for a in arrays: t = a.typecode() kind = max(kind, _array_kind[t]) precision = max(precision, _array_precision[t]) return _array_type[kind][precision] def _castCopyAndTranspose(type, *arrays): cast_arrays = () for a in arrays: if a.typecode() == type: cast_arrays = cast_arrays + (copy.copy(Numeric.transpose(a)),) else: cast_arrays = cast_arrays + (copy.copy( Numeric.transpose(a).astype(type)),) if len(cast_arrays) == 1: return cast_arrays[0] else: return cast_arrays def _assertRank2(*arrays): for a in arrays: if len(a.shape) != 2: raise LinAlgError, 'Array must be two-dimensional' def _assertSquareness(*arrays): for a in arrays: if max(a.shape) != min(a.shape): raise LinAlgError, 'Array must be square' # Linear equations def solve_linear_equations(a, b): one_eq = len(b.shape) == 1 if one_eq: b = b[:, Numeric.NewAxis] _assertRank2(a, b) _assertSquareness(a) n_eq = a.shape[0] n_rhs = b.shape[1] if n_eq != b.shape[0]: raise LinAlgError, 'Incompatible dimensions' t =_commonType(a, b) # lapack_routine = _findLapackRoutine('gesv', t) if _array_kind[t] == 1: # Complex routines take different arguments lapack_routine = lapack_lite.zgesv else: lapack_routine = lapack_lite.dgesv a, b = _castCopyAndTranspose(t, a, b) pivots = Numeric.zeros(n_eq, 'l') results = lapack_routine(n_eq, n_rhs, a, n_eq, pivots, b, n_eq, 0) if results['info'] > 0: raise LinAlgError, 'Singular matrix' if one_eq: return copy.copy(Numeric.ravel(b)) else: return copy.copy(Numeric.transpose(b)) # Matrix inversion def inverse(a): return solve_linear_equations(a, Numeric.identity(a.shape[0])) # Eigenvalues def eigenvalues(a): _assertRank2(a) _assertSquareness(a) t =_commonType(a) real_t = _array_type[0][_array_precision[t]] a = _castCopyAndTranspose(t, a) n = a.shape[0] dummy = Numeric.zeros((1,), t) lwork = max(1,6*n) # minimum value: max(1,3*n) real, max(1,2*n) complex work = Numeric.zeros((lwork,), t) if _array_kind[t] == 1: # Complex routines take different arguments lapack_routine = lapack_lite.zgeev w = Numeric.zeros((n,), t) rwork = Numeric.zeros((n,),real_t) results = lapack_routine('N', 'N', n, a, n, w, dummy, 1, dummy, 1, work, lwork, rwork, 0) else: lapack_routine = lapack_lite.dgeev wr = Numeric.zeros((n,), t) wi = Numeric.zeros((n,), t) results = lapack_routine('N', 'N', n, a, n, wr, wi, dummy, 1, dummy, 1, work, lwork, 0) if Numeric.logical_and.reduce(Numeric.equal(wi, 0.)): w = wr else: w = wr+1j*wi if results['info'] > 0: raise LinAlgError, 'Eigenvalues did not converge' return w # Eigenvectors def eigenvectors(a): """eigenvectors(a) returns u,v where u is the eigenvalues and v is a matrix of eigenvectors with vector v[i] corresponds to eigenvalue u[i]. Satisfies the equation matrixmultiply(a, v[i]) = u[i]*v[i] """ _assertRank2(a) _assertSquareness(a) t =_commonType(a) real_t = _array_type[0][_array_precision[t]] a = _castCopyAndTranspose(t, a) n = a.shape[0] lwork = max(1,8*n) # minimum value: max(1,4*n) real, max(1,2*n) complex work = Numeric.zeros((lwork,), t) dummy = Numeric.zeros((1,), t) if _array_kind[t] == 1: # Complex routines take different arguments lapack_routine = lapack_lite.zgeev w = Numeric.zeros((n,), t) rwork = Numeric.zeros((lwork,),real_t) v = Numeric.zeros((n,n), t) results = lapack_routine('N', 'V', n, a, n, w, dummy, 1, v, n, work, lwork, rwork, 0) else: lapack_routine = lapack_lite.dgeev wr = Numeric.zeros((n,), t) wi = Numeric.zeros((n,), t) vr = Numeric.zeros((n,n), t) results = lapack_routine('N', 'V', n, a, n, wr, wi, dummy, 1, vr, n, work, lwork, 0) if Numeric.logical_and.reduce(Numeric.equal(wi, 0.)): w = wr v = vr else: w = wr+1j*wi v = Numeric.array(vr,Numeric.Complex) ind = Numeric.nonzero( Numeric.equal( Numeric.equal(wi,0.0) # true for real e-vals ,0) # true for complex e-vals ) # indices of complex e-vals for i in range(len(ind)/2): v[ind[2*i]] = vr[ind[2*i]] + 1j*vr[ind[2*i+1]] v[ind[2*i+1]] = vr[ind[2*i]] - 1j*vr[ind[2*i+1]] if results['info'] > 0: raise LinAlgError, 'Eigenvalues did not converge' return w,v # Singular value decomposition def singular_value_decomposition(a): _assertRank2(a) n = a.shape[1] m = a.shape[0] t =_commonType(a) real_t = _array_type[0][_array_precision[t]] a = _castCopyAndTranspose(t, a) s = Numeric.zeros((min(n,m),), real_t) u = Numeric.zeros((m, m), t) lwork = 10*max(m,n) # minimum value: max(3*min(m,n)+max(m,n),5*min(m,n)-4) work = Numeric.zeros((lwork,), t) vt = Numeric.zeros((n, n), t) if _array_kind[t] == 1: # Complex routines take different arguments lapack_routine = lapack_lite.zgesvd rwork = Numeric.zeros((max(3*min(m,n),5*min(m,n)-4),), real_t) results = lapack_routine('A', 'A', m, n, a, m, s, u, m, vt, n, work, lwork, rwork, 0) else: lapack_routine = lapack_lite.dgesvd results = lapack_routine('A', 'A', m, n, a, m, s, u, m, vt, n, work, lwork, 0) if results['info'] > 0: raise LinAlgError, 'SVD did not converge' return copy.copy(Numeric.transpose(u)), s, copy.copy(Numeric.transpose(vt)) # Generalized inverse def generalized_inverse(a): u, s, vt = singular_value_decomposition(a) m = u.shape[0] n = vt.shape[0] cutoff = 1.e-10*Numeric.maximum.reduce(s) sm = Numeric.zeros((n, m), s.typecode()) for i in range(min(n,m)): if s[i] > cutoff: sm[i,i] = 1./s[i] return Numeric.matrixmultiply(Numeric.matrixmultiply(Numeric.transpose(vt), sm), Numeric.transpose(u)) # Determinant def determinant(a): _assertRank2(a) _assertSquareness(a) ev = eigenvalues(a) return Numeric.product(ev) # Linear Least Squares def linear_least_squares(a, b, rcond=1.e-10): """solveLinearLeastSquares(a,b) returns x,resids,rank,s where x minimizes 2-norm(|b - Ax|) resids is the sum square residuals rank is the rank of A s is an rank of the singual values of A in desending order If b is a matrix then x is also a matrix with corresponding columns. If the rank of A is less than the number of columns of A or greater than the numer of rows, then residuals will be returned as an empty array otherwise resids = sum((b-dot(A,x)**2). Singular values less than s[0]*rcond are treated as zero. """ one_eq = len(b.shape) == 1 if one_eq: b = b[:, Numeric.NewAxis] _assertRank2(a, b) m = a.shape[0] n = a.shape[1] n_rhs = b.shape[1] ldb = max(n,m) if m != b.shape[0]: raise LinAlgError, 'Incompatible dimensions' t =_commonType(a, b) real_t = _array_type[0][_array_precision[t]] bstar = Numeric.zeros((ldb,n_rhs),t) bstar[:b.shape[0],:n_rhs] = copy.copy(b) a,bstar = _castCopyAndTranspose(t, a, bstar) lwork = 8*min(n,m) + max([2*min(m,n),max(m,n),n_rhs]) s = Numeric.zeros((min(m,n),),real_t) work = Numeric.zeros((lwork,), t) if _array_kind[t] == 1: # Complex routines take different arguments lapack_routine = lapack_lite.zgelss rwork = Numeric.zeros((5*min(m,n)-1,), real_t) results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond, 0,work,lwork,rwork,0 ) else: lapack_routine = lapack_lite.dgelss results = lapack_routine( m, n, n_rhs, a, m, bstar,ldb , s, rcond, 0,work,lwork,0 ) if results['info'] > 0: raise LinAlgError, 'SVD did not converge in Linear Least Squares' resids = Numeric.array([],t) if one_eq: x = copy.copy(Numeric.ravel(bstar)[:n]) if (results['rank']==n) and (m>n): resids = Numeric.array([Numeric.sum((Numeric.ravel(bstar)[n:])**2)]) else: x = copy.copy(Numeric.transpose(bstar)[:n,:]) if (results['rank']==n) and (m>n): resids = copy.copy(Numeric.sum((Numeric.transpose(bstar)[n:,:])**2)) return x,resids,results['rank'],copy.copy(s[:min(n,m)]) _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From hinsen@ibs.ibs.fr Sun Feb 23 09:35:08 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Sun, 23 Feb 1997 10:35:08 +0100 Subject: [PYTHON MATRIX-SIG] Elementary test suite for LinearAlgebra In-Reply-To: <01BC2008.4BF62120@misha.lcs.mit.edu> (message from Jim Hugunin on Fri, 21 Feb 1997 15:02:41 -0500) Message-ID: <199702230935.KAA17500@lmspc2.ibs.fr> from Numeric import * from LinearAlgebra import * def test(a, b): print "All numbers printed should be (almost) zero:" x = solve_linear_equations(a, b) check = b - matrixmultiply(a, x) print check a_inv = inverse(a) check = matrixmultiply(a, a_inv)-identity(a.shape[0]) print check ev = eigenvalues(a) evalues, evectors = eigenvectors(a) check = ev-evalues print check evectors = transpose(evectors) check = matrixmultiply(a, evectors)-evectors*evalues print check u, s, vt = singular_value_decomposition(a) check = a - Numeric.matrixmultiply(u*s, vt) print check a_ginv = generalized_inverse(a) check = matrixmultiply(a, a_ginv)-identity(a.shape[0]) print check det = determinant(a) check = det-multiply.reduce(evalues) print check x, residuals, rank, sv = linear_least_squares(a, b) check = b - matrixmultiply(a, x) print check print rank-a.shape[0] print sv-s a = array([[1.,2.], [3.,4.]]) b = array([2., 1.]) test(a, b) a = a+0j b = b+0j test(a, b) _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From hinsen@ibs.ibs.fr Sun Feb 23 09:32:55 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Sun, 23 Feb 1997 10:32:55 +0100 Subject: [PYTHON MATRIX-SIG] Numeric Python Beta 1 Released! In-Reply-To: <01BC2008.4BF62120@misha.lcs.mit.edu> (message from Jim Hugunin on Fri, 21 Feb 1997 15:02:41 -0500) Message-ID: <199702230932.KAA17482@lmspc2.ibs.fr> > I kept saying it was going to happen any day now...today's that day. And it partly ruined my day, since of course I couldn't resist installing and testing the new version immediately, although I had only come to start a calculation job :-( So far for the first complaint ;-) > Check out http://www.sls.lcs.mit.edu/~jjh/numpy for the first beta release > of NumPy. It includes a source distribution that will work under both > windows and unix, and an easy to install binary for Win NT/95. Grab it, > install it, and let me know what you think (feel free to comment on the web > pages as well...). The Web page is fine, I didn't expect such a luxury! Maybe you should add pointers to code based on NumPy; I'll start immodestly by proposing my own: http://yi.com/home/HinsenKonrad/python.html http://yi.com/home/HinsenKonrad/netcdf.html Other stuff that comes to mind is the full LAPACK interface and the Gist interface. > Unix installation instructions need work, more info for different OS's I corrected the installation instructions for the first choice (installation in the Python source tree); I'll send the new version around to everyone so that others can check whether it's OK for them. I did not try the second choice, but I strongly suspect that the instructions are incomplete. The shared libraries will end up in NumPy, whereas the Python modules are in NumPy/NumPy. So *both* directories must be added to PYTHONPATH, or one or the other set of files must be copied. Personally I'd prefer to copy some files rather than mess up my PYTHONPATH needlessly, but I'd rather let the people who use it decide. I remember some reports about problems with the second installation method on some machines due to the shared library libnumpymodule. That ought to be mentioned somewhere with a list of affected machines. > Bug fixes (all known bugs are squashed in this release...) I found only one trivial bug in the new release: test/test_all.py fails under Unix with a syntax error because of the CRs in the file test_items.py. They should be removed. There have been a couple of bugs in LinearAlgebra.py for a while, which I have corrected in the course of time, but never sent to anyone. I have now done some superficial test of all functions, and I'll send the fixed file plus my "test suite" around to everyone - it would be good to have this tested on other machines as well. I'll try to improve some functions later, but that won't change the interface, so it's not urgent. > questions about the system to the matrix-sig. I fear that I've lost many > of the comments sent to me over the last five months due to a period of > immense disorganization in my life. I'm now much better set up to collect > bug reports and feature suggestions, so if I haven't addressed your > comments in this latest release, please send them to me again. I still think that it would be better to give Numeric.dot() the functionality of Numeric.matrixmultiply() and remove the latter (or keep it for compatibility, but not document it). There is no need for two functions, and many people will probably use dot() although what they need is matrixmultiply(). I also still think that the generalized version of diagonal() and trace() that I posted a while ago would be more suitable than the current version that works only on rank-2 arrays. Here's my version again: ------------------------------------------------------------ def diagonal(a, axis1=0, axis2=1, offset=0): a = array(a) if axis2 < axis1: axis1, axis2 = axis2, axis1 if axis2 > 1: new_axes = range(len(a.shape)) del new_axes[axis2]; del new_axes[axis1] new_axes[0:0] = [axis1, axis2] a = transpose(a, new_axes) s = a.shape n1 = s[0] n2 = s[1] n = n1*n2 s = (n,) + s[2:] a = reshape(a, s) if offset < 0: offset = n2-offset-1 return take(a, arange(offset, n, n2+1), 0) def trace(a, axis1=0, axis2=1, offset=0): return add.reduce(diagonal(a, axis1, axis2, offset)) ------------------------------------------------------------ That's it for now, more complaints later ;-) Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen@ibs.ibs.fr Laboratoire de Dynamique Moleculaire | Tel.: +33-4.76.88.99.28 Institut de Biologie Structurale | Fax: +33-4.76.88.54.94 41, av. des Martyrs | Deutsch/Esperanto/English/ 38027 Grenoble Cedex 1, France | Nederlands/Francais ------------------------------------------------------------------------------- _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From acannon@geog.ubc.ca Sun Feb 23 23:40:27 1997 From: acannon@geog.ubc.ca (Alex Cannon) Date: Sun, 23 Feb 1997 15:40:27 -0800 (PST) Subject: [PYTHON MATRIX-SIG] Win95 NumPy 1.0b1 install problem In-Reply-To: <199702230933.KAA17488@lmspc2.ibs.fr> Message-ID: I've just downloaded and executed the NumPy 1.0b1 binary for Win95/NT and am getting: ! Please run this installation in a DOS box. It doesn't appear that a setup executable etc. is being extracted. Has anyone else experienced a similar problem? This is with Win95 4.00.950a. Alex ------------------------------------------------------------ Alex Cannon (acannon@geog.ubc.ca) Geography 240A Atmospheric Science Programme Tel: (604) 822-2269 University of British Columbia, B.C. Fax: (604) 822-6150 _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From amullhau@ix.netcom.com Mon Feb 24 00:09:44 1997 From: amullhau@ix.netcom.com (Andrew P. Mullhaupt) Date: Sun, 23 Feb 1997 19:09:44 -0500 Subject: [PYTHON MATRIX-SIG] Win95 NumPy 1.0b1 install problem References: Message-ID: <3310DC48.724A@ix.netcom.com> Alex Cannon wrote: > > I've just downloaded and executed the NumPy 1.0b1 binary for Win95/NT and > am getting: > > ! > Please run this installation > > in a DOS box. It doesn't appear that a setup executable etc. is being > extracted. Has anyone else experienced a similar problem? This is with > Win95 4.00.950a. I have the same. However, at least PythonWin no longer crashes all the time. Later, Andrew Mullhaupt _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From ta.short@pti-us.com Mon Feb 24 16:16:42 1997 From: ta.short@pti-us.com (Tom Short) Date: Mon, 24 Feb 1997 11:16:42 -0500 (EST) Subject: [PYTHON MATRIX-SIG] Win95 NumPy 1.0b1 install problem Message-ID: <3.0.1.16.19970224111628.2bdf4e9a@mailhost1473> At 07:09 PM 2/23/97 -0500, you wrote: >Alex Cannon wrote: >> >> I've just downloaded and executed the NumPy 1.0b1 binary for Win95/NT and >> am getting: >> >> ! >> Please run this installation >> >> in a DOS box. It doesn't appear that a setup executable etc. is being >> extracted. Has anyone else experienced a similar problem? This is with >> Win95 4.00.950a. > I got this too but then noticed that the file size was not right (should be 408,830 bytes), so Netscape didn't download it correctly (I think it might be trying to fetch it as text instead of binary). I used another web download tool (webfetch), and it worked okay. - Tom _______________ 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 Mon Feb 24 16:36:01 1997 From: barton@simsg1.mdc.com (Brien Barton) Date: Mon, 24 Feb 1997 08:36:01 -0800 Subject: [PYTHON MATRIX-SIG] Win95 NumPy 1.0b1 install problem References: <3310DC48.724A@ix.netcom.com> Message-ID: <3311C371.41C6@simsg1.mdc.com> Andrew P. Mullhaupt wrote: > > Alex Cannon wrote: > > > > I've just downloaded and executed the NumPy 1.0b1 binary for Win95/NT and > > am getting: > > > > ! > > Please run this installation > > > > in a DOS box. It doesn't appear that a setup executable etc. is being > > extracted. Has anyone else experienced a similar problem? This is with > > Win95 4.00.950a. I executed the NumPy installation binary by double clicking on it from Explorer and it installed fine. -- Brien Barton _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From hugunin@mit.edu Mon Feb 24 17:05:42 1997 From: hugunin@mit.edu (Jim Hugunin) Date: Mon, 24 Feb 1997 12:05:42 -0500 Subject: [PYTHON MATRIX-SIG] Win95 NumPy 1.0b1 install problem Message-ID: <01BC224B.0F6155A0@misha.lcs.mit.edu> I just changed the file name on the web page from NumPy-10-b1.EXE to NumPy-10-b1.exe. This was the only thing I could see about the link that might have been causing Netscape confusion over the file's format. Those of you who have had problems should try downloading from this new link and see if it fixes things. As mentioned before, the file should have a size of 408,830 bytes when downloaded to your system. If this is not the case, then there's something wrong with your transfer. Let me know if this works/fails - Jim _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From hinsen@ibs.ibs.fr Mon Feb 24 18:22:59 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Mon, 24 Feb 1997 19:22:59 +0100 Subject: [PYTHON MATRIX-SIG] HP problem Message-ID: <199702241822.TAA22379@lmspc2.ibs.fr> Just in case anyone else tries the new NumPy under HP/UX 9.01: it seems the HP compiler can't handle dlapack_lite.c and zlapack_lite.c; it crashes with an "internal error" and asks me to contact HP support. There may of course be some patch that fixes this, but the easiest solution is to use gcc, which works fine, or to use the Fortran LAPACK, which is probably the best solution. Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen@ibs.ibs.fr Laboratoire de Dynamique Moleculaire | Tel.: +33-4.76.88.99.28 Institut de Biologie Structurale | Fax: +33-4.76.88.54.94 41, av. des Martyrs | Deutsch/Esperanto/English/ 38027 Grenoble Cedex 1, France | Nederlands/Francais ------------------------------------------------------------------------------- _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From susan@pcmdi.llnl.gov Mon Feb 24 18:53:43 1997 From: susan@pcmdi.llnl.gov (Susan Peterson) Date: Mon, 24 Feb 1997 10:53:43 -0800 Subject: [PYTHON MATRIX-SIG] Installing New Numerics Message-ID: <9702241053.ZM29541@penguin.llnl.gov> Hi, I've installed the new Numerics, but the test program isn't running. After removing the CRs in the test_items.py file, when I run the test_all.py I get the following error (after it has run for awhile) Traceback (innermost last): File "test_all.py", line 48, in ? test_lines(fp.readlines()) File "test_all.py", line 29, in test_lines out = eval(line) File "", line 0, in ? NameError: searchsorted Any ideas what I should do? Please reply to susan@pcmdi.llnl.gov Thanks in advance for your help. -Susan -- Susan Peterson _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From susan@pcmdi.llnl.gov Mon Feb 24 18:55:43 1997 From: susan@pcmdi.llnl.gov (Susan Peterson) Date: Mon, 24 Feb 1997 10:55:43 -0800 Subject: No subject Message-ID: <9702241055.ZM29560@penguin.llnl.gov> Hi, I've installed the new Numerics, but the test program isn't running. After removing the CRs in the test_items.py file, when I run the test_all.py I get the following error (after it has run for awhile) Traceback (innermost last): File "test_all.py", line 48, in ? test_lines(fp.readlines()) File "test_all.py", line 29, in test_lines out = eval(line) File "", line 0, in ? NameError: searchsorted Any ideas what I should do? Please reply to susan@pcmdi.llnl.gov Thanks in advance for your help. -Susan -- Susan Peterson _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From furnish@laura.llnl.gov Mon Feb 24 20:23:31 1997 From: furnish@laura.llnl.gov (Geoffrey Furnish) Date: Mon, 24 Feb 1997 12:23:31 -0800 Subject: [PYTHON MATRIX-SIG] HP problem In-Reply-To: <199702241822.TAA22379@lmspc2.ibs.fr> References: <199702241822.TAA22379@lmspc2.ibs.fr> Message-ID: <199702242026.PAA10383@python.org> Konrad Hinsen writes: > Just in case anyone else tries the new NumPy under HP/UX 9.01: it seems > the HP compiler can't handle dlapack_lite.c and zlapack_lite.c; it > crashes with an "internal error" and asks me to contact HP support. > There may of course be some patch that fixes this, but the easiest > solution is to use gcc, which works fine, or to use the Fortran > LAPACK, which is probably the best solution. Using gcc is not really fine except under certain conditions. If you try to compile with -g, you can't make a shared module b/c of problems with the size of some symbol table (and using -fPIC doesn't solve the problem). Exactly /how/ does one configure out the lapack_lite stuff and switch to using the fortran versions. That has not been convered in anything I've personally read. -- Geoffrey Furnish email: furnish@llnl.gov LLNL X/ICF phone: 510-424-4227 fax: 510-423-0925 _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From hugunin@mit.edu Mon Feb 24 21:29:21 1997 From: hugunin@mit.edu (Jim Hugunin) Date: Mon, 24 Feb 1997 16:29:21 -0500 Subject: [PYTHON MATRIX-SIG] RE: NameError: searchsorted Message-ID: <01BC226F.E47B4790@misha.lcs.mit.edu> Susan Peterson writes: > Hi, > > I've installed the new Numerics, but the test program isn't running. > After removing the CRs in the test_items.py file, when I run the > test_all.py I get the following error (after it has run for awhile) > > Traceback (innermost last): > File "test_all.py", line 48, in ? > test_lines(fp.readlines()) > File "test_all.py", line 29, in test_lines > out = eval(line) > File "", line 0, in ? > NameError: searchsorted > > Any ideas what I should do? This error indicates that you are referencing an old version of Numeric.py. This could either be due to a path problem pointing to an old installation, or due to an old .pyc file being used instead of the new .py. Hope this helps - Jim _______________ 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 Mon Feb 24 23:53:08 1997 From: barton@simsg1.mdc.com (Brien Barton) Date: Mon, 24 Feb 1997 15:53:08 -0800 (PST) Subject: [PYTHON MATRIX-SIG] NumPy test failing Message-ID: I installed the new NumPy 1.0b1 on an SGI system and tried to run the test_all.py script. It gets an error on the test that tries to verify that, if a is an array, then array(a) returns a copy of a. The lines from test_items.py are: b = array(a) b[0] = 66 a[0] >0 This test is apparently trying to verify that after the line "b = array(a)", b and a are two different objects, but on my system they are the same. Anyone else seeing this? -- Brien =============================================================================== Brien Barton ISSC Corp, c/o McDonnell Douglas Space & Defense Systems Huntington Beach, CA email: barton@simsg1.mdc.com, voice: (714)896-2249, fax:(714)896-5939 "My witty proclivities are nothing compared to my ludicrous ineptitudes." - Bob Hope =============================================================================== _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From amullhau@ix.netcom.com Tue Feb 25 03:46:59 1997 From: amullhau@ix.netcom.com (Andrew P. Mullhaupt) Date: Mon, 24 Feb 1997 22:46:59 -0500 Subject: [PYTHON MATRIX-SIG] Win95 NumPy 1.0b1 install problem References: <01BC224B.0F6155A0@misha.lcs.mit.edu> Message-ID: <331260B3.7B5E@ix.netcom.com> Jim Hugunin wrote: > > As mentioned before, the file should have a size of 408,830 bytes when > downloaded to your system. If this is not the case, then there's something > wrong with your transfer. God only knows what is going on here. I tried again, and the download put the file in NumPy-10-b1.txt. It wsa the right size, though, and after renaming, it ran, claiming to have installed NumPy. PythonWin doesn't seem to be all that numeric yet, since resize(0, [2, 2]) results in a NameError. Maybe after rebooting this will be better. Later, Andrew Mullhaupt _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From jhauser@ifm.uni-kiel.de Tue Feb 25 09:06:48 1997 From: jhauser@ifm.uni-kiel.de (janko hauser) Date: Tue, 25 Feb 1997 10:06:48 +0100 Subject: [PYTHON MATRIX-SIG] inconsistency in array()? Message-ID: <9702250906.AA08749@flores.ifm.uni-kiel.de> Hello, I have tried the new NumPy-beta. I first had some problems with the path, I mixed up the old and the new distribution. I hope that the next points are unaffected by this :-) I think the asarray() function is broken, and with this the shape() function too. In Numeric.py (+244) array() is called with a keyword, wich it doesn't understand. I had a look in the old and new multiarray-code and the former method asarray has changed to a Numeric function. Is this right? And why, may I ask? UserArray is broken but I append a version wich hopefully is ok. (It is broken, because it is not possible to use less() or something like that) There is one remaining problem, because I can't make a reference to a slice of the UserArray-object, I only get copys, wich is suboptimal. Any suggestions? :-) The benefit of the new implementation is, that I can use all functions with an instance of this class, without definig them in the UserArray-class. __Janko Here comes a new UserArray: (If there are bugs, please shout loud, I need this class) ## --------------- cut here ---------------------------------------- #!/usr/local/bin/python from Numeric import * import string class UserArray: def __init__(self, data, typecode = None): # Needs more testing if typecode == None: self.array = asarray(data) else: self.array = array(data, typecode) self.shape = self.array.shape self.typecode = self.array.typecode() self.name = string.split(str(self.__class__))[1] def __repr__(self): return self.name+"\n"+str(self.array) def __array__(self,t=None): if t: return asarray(self.array,t) return asarray(self.array) def __float__(self): return float(asarray(self.array)) # Array as sequence def __len__(self): return len(self.array) def __getitem__(self, index): return self._rc(self.array[index]) def __getslice__(self, i, j): return self._rc(self.array[i:j]) def __setitem__(self, index, value): self.array[index] = asarray(value,self.typecode) def __setslice__(self, i, j, value): self.array[i:j] = asarray(value) def __del__(self): for att in dir(self): delattr(self,att) #del(self) def __abs__(self): return self._rc(absolute(self.array)) def __neg__(self): return self._rc(-self.array) def __add__(self, other): return self._rc(self.array+asarray(other)) __radd__ = __add__ def __sub__(self, other): return self._rc(self.array-asarray(other)) def __rsub__(self, other): return self._rc(asarray(other)-self.array) def __mul__(self, other): return self._rc(multiply(self.array,asarray(other))) __rmul__ = __mul__ def __div__(self, other): return self._rc(divide(self.array,asarray(other))) def __rdiv__(self, other): return self._rc(divide(asarray(other),self.array)) def __pow__(self,other): return self._rc(power(self.array,asarray(other))) def __rpow__(self,other): return self._rc(power(asarray(other),self.array)) def __sqrt__(self): return self._rc(sqrt(self.array)) def tostring(self): return self.array.tostring() def byteswapped(self): return self._rc(self.array.byteswapped()) def asType(self, typecode): return self._rc(self.array.asType(typecode)) def typecode(self): return self.array.typecode() def itemsize(self): return self.array.itemsize() def isContiguous(self): return self.array.isContiguous() UserArray._rc=UserArray ############################################################# # Test of class UserArray ############################################################# if __name__ == '__main__': import Numeric temp=reshape(arange(10000),(100,100)) ua=UserArray(temp) # new object created begin test print dir(ua) print shape(ua),ua.shape # I have changed Numeric.py ua_small=ua[:3,:5] print ua_small ua_small[0,0]=10 # this did not change ua[0,0], wich is not normal behavior print ua_small[0,0],ua[0,0] print sin(ua_small)/3.*6.+sqrt(ua_small**2) print less(ua_small,103),type(less(ua_small,103)) print type(ua_small*reshape(arange(15),shape(ua_small))) print reshape(ua_small,(5,3)) print transpose(ua_small) _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From hinsen@ibs.ibs.fr Tue Feb 25 09:24:45 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Tue, 25 Feb 1997 10:24:45 +0100 Subject: [PYTHON MATRIX-SIG] HP problem In-Reply-To: <199702242026.PAA10383@python.org> (message from Geoffrey Furnish on Mon, 24 Feb 1997 12:23:31 -0800) Message-ID: <199702250924.KAA24804@lmspc2.ibs.fr> > Using gcc is not really fine except under certain conditions. If you > try to compile with -g, you can't make a shared module b/c of problems > with the size of some symbol table (and using -fPIC doesn't solve the > problem). True, but I see no reason to compile the LAPACK code with -g. I use gcc only for the two modules that cc can't handle, so that shouldn't cause too much trouble. > Exactly /how/ does one configure out the lapack_lite stuff and switch > to using the fortran versions. That has not been convered in anything > I've personally read. Because it's machine dependent. Here are the instructions for HP/UX: 1) Get the LAPACK/BLAS source code and compile it as position-independent code (note: the precompiled LAPACK on netlib is not position-independent). 2) Change the Setup line for lapack_lite to lapack_lite -DNO_APPEND_FORTRAN -I../NumPy/Include -I../NumPy/NumPyLib ../NumPy/lapack_litemodule.c -L/usr/local/lib -llapack -lblas -lcl -lm Of course you have to change the -L option to point to your copy of LAPACK and BLAS. It would be nice if others could contribute appropriate instructions for their machines for a collection of "optimization hints" for NumPy. Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen@ibs.ibs.fr Laboratoire de Dynamique Moleculaire | Tel.: +33-4.76.88.99.28 Institut de Biologie Structurale | Fax: +33-4.76.88.54.94 41, av. des Martyrs | Deutsch/Esperanto/English/ 38027 Grenoble Cedex 1, France | Nederlands/Francais ------------------------------------------------------------------------------- _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From valb@vtek.com Tue Feb 25 14:41:21 1997 From: valb@vtek.com (Val Bykoski) Date: Tue, 25 Feb 1997 09:41:21 -0500 Subject: [PYTHON MATRIX-SIG] switch to Explorer... Message-ID: <199702251436.JAA20738@lucius.ultra.net> Hi, folks! I had all the messy problems with the download - dozens of unsuccessful attempts. When I switched from Netscape to Explorer 3.0, everything was fine and smooth including installation and testing. --Val _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From hugunin@mit.edu Tue Feb 25 17:54:58 1997 From: hugunin@mit.edu (Jim Hugunin) Date: Tue, 25 Feb 1997 12:54:58 -0500 Subject: [PYTHON MATRIX-SIG] NumPy test failing Message-ID: <01BC231B.1BAB6DC0@misha.lcs.mit.edu> Brien Barton writes: > I installed the new NumPy 1.0b1 on an SGI system and tried to run the > test_all.py script. It gets an error on the test that tries to verify that, > if a is an array, then array(a) returns a copy of a. The lines from > test_items.py are: > > b = array(a) > b[0] = 66 > a[0] > >0 > > This test is apparently trying to verify that after the line "b = array(a)", > b and a are two different objects, but on my system they are the same. > Anyone else seeing this? This is a bug related to the new support I added to the array function for keyword arguments. If you use b = array(a, copy=1) explicitly this will work. Otherwise, I've fixed this and it shouldn't be a problem in the next beta 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 hugunin@mit.edu Tue Feb 25 17:57:59 1997 From: hugunin@mit.edu (Jim Hugunin) Date: Tue, 25 Feb 1997 12:57:59 -0500 Subject: [PYTHON MATRIX-SIG] Win95 NumPy 1.0b1 install problem Message-ID: <01BC231B.87CE3AA0@misha.lcs.mit.edu> Andrew writes: > Jim Hugunin wrote: > > > > As mentioned before, the file should have a size of 408,830 bytes when > > downloaded to your system. If this is not the case, then there's something > > wrong with your transfer. > > God only knows what is going on here. I tried again, and the download > put the file in NumPy-10-b1.txt. It wsa the right size, though, and > after renaming, it ran, claiming to have installed NumPy. PythonWin > doesn't seem to be all that numeric yet, since > > resize(0, [2, 2]) > > results in a NameError. > > Maybe after rebooting this will be better. I hate to ask the obvious question, but have you typed "from Numeric import *"? The Numeric extensions are an extension like any other and need to be imported into Python before they can be used. If the problem is more complicated than this, then I'm at a loss. More information would be helpful. -Jim _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From hugunin@mit.edu Tue Feb 25 18:09:06 1997 From: hugunin@mit.edu (Jim Hugunin) Date: Tue, 25 Feb 1997 13:09:06 -0500 Subject: [PYTHON MATRIX-SIG] inconsistency in array()? Message-ID: <01BC231D.14724C70@misha.lcs.mit.edu> Janko Hauser writes: > Hello, I have tried the new NumPy-beta. I first had some problems with > the path, I mixed up the old and the new distribution. I hope that the > next points are unaffected by this :-) I'm afraid that these problems sound like they are in fact related to mixing up the old and new distributions. > I think the asarray() function is broken, and with this the shape() > function too. In Numeric.py (+244) array() is called with a keyword, > wich it doesn't understand. I had a look in the old and new > multiarray-code and the former method asarray has changed to a Numeric > function. Is this right? And why, may I ask? asarray has always been a function in Numeric.py. Chris Chase made some patches available to the matrix-sig that moved it into multiarray.c to fix some problems with user defined array classes. I adopted his patches, but instead of adding a new C function for asarray, I modified the existing array function to give the supported needed (without changing its previous behavior). In modifying the array function, I added support for keyword arguments to it (using hooks Guido added to Python1.4). This is the first C function in Numeric to support keyword arguments, but if all goes well it will make things like "add.reduce(a, axis=12)" possible in future versions. If your array function doesn't understand keyword arguments, then you are working with an old version of the multiarray module. > UserArray is broken but I append a version wich hopefully is ok. (It > is broken, because it is not possible to use less() or something like > that) There is one remaining problem, because I can't make a > reference to a slice of the UserArray-object, I only get copys, wich > is suboptimal. Any suggestions? :-) I hadn't checked out UserArray closely enough (I don't use it personally). Yours looks like a good improvement and if I don't hear any complaints about it on the list, I'll adopt it into 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 hugunin@mit.edu Tue Feb 25 19:30:44 1997 From: hugunin@mit.edu (Jim Hugunin) Date: Tue, 25 Feb 1997 14:30:44 -0500 Subject: [PYTHON MATRIX-SIG] inconsistency in array()? Message-ID: <01BC2328.7C51C950@misha.lcs.mit.edu> Tom Short writes: > >I hadn't checked out UserArray closely enough (I don't use it personally). > > Yours looks like a good improvement and if I don't hear any complaints > >about it on the list, I'll adopt it into the next release. > > What is the purpose of UserArray? What does it allow that an Array doesn't? UserArray is a python class that behaves as much as possible like the lower level array objects that are in C. The main advantage to UserArray is that it can be subclassed to provide particular behaviors, while still behaving as a normal array wherever possible. The simplest example of the use of UserArray is the Matrix class that behaves like the built-in array objects in most ways, but that reimplements the multiply operation to do "real" matrix multiplies rather than the normal element-wise multiplications. I hope this answers your question - Jim _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From amullhau@ix.netcom.com Tue Feb 25 23:38:42 1997 From: amullhau@ix.netcom.com (Andrew P. Mullhaupt) Date: Tue, 25 Feb 1997 18:38:42 -0500 Subject: [PYTHON MATRIX-SIG] Win95 NumPy 1.0b1 install problem References: <01BC231B.8847D770@misha.lcs.mit.edu> Message-ID: <33137802.6815@ix.netcom.com> Jim Hugunin wrote: > > Andrew writes: > > > resize(0, [2, 2]) > > > > results in a NameError. > > > > Maybe after rebooting this will be better. > > I hate to ask the obvious question, but have you typed "from Numeric import > *"? The Numeric extensions are an extension like any other and need to be > imported into Python before they can be used. > > If the problem is more complicated than this, then I'm at a loss. More > information would be helpful. Yes, I did type "from Numeric import *" _After rebooting_, we no longer get the NameError, and what happens is that the correct object is created, although arrays print out as array([[1, 2, 3, 4], [5, 6, 7, 8]], 'l') as opposed to 1 2 3 4 5 6 7 8 This problem does not occur with the version I built on my Ultrasparc (Solaris 2.5.1). I don't yet have a lot of code which tests NumPy so I don't really know what works and what doesn't yet; but I don't notice any problems on the Unix version. Later, Andrew Mullhaupt _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From furnish@laura.llnl.gov Wed Feb 26 16:12:55 1997 From: furnish@laura.llnl.gov (Geoffrey Furnish) Date: Wed, 26 Feb 1997 08:12:55 -0800 Subject: [PYTHON MATRIX-SIG] HP problem In-Reply-To: <199702250924.KAA24804@lmspc2.ibs.fr> References: <199702242026.PAA10383@python.org> <199702250924.KAA24804@lmspc2.ibs.fr> Message-ID: <199702261616.LAA23323@python.org> Konrad Hinsen writes: > > Using gcc is not really fine except under certain conditions. If you > > try to compile with -g, you can't make a shared module b/c of problems > > with the size of some symbol table (and using -fPIC doesn't solve the > > problem). > > True, but I see no reason to compile the LAPACK code with -g. I use > gcc only for the two modules that cc can't handle, so that shouldn't > cause too much trouble. The way it happened to me seems innocent enough: I tried to build a debuggable Python, so everything got compiled with -g, and the NumPy stuff wouldn't compile/link. Python's build procedure is not very well configured for the purpose of selectively compiling different parts with different options, and linking them all together. This seems understandable to me, since that would be a monster autoconf job. Instead, it would seem much more reasonable if the entire code base could be compiled -g. NumPy is the only portion of Python I am aware of which makes this problematic. In any event, I am not currently trying to build a debuggable Python, so for me, this is moot at the present time. > > Exactly /how/ does one configure out the lapack_lite stuff and switch > > to using the fortran versions. That has not been convered in anything > > I've personally read. > > Because it's machine dependent. Here are the instructions for HP/UX: > [...] Thanks. -- Geoffrey Furnish email: furnish@llnl.gov LLNL X/ICF phone: 510-424-4227 fax: 510-423-0925 _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From hugunin@mit.edu Wed Feb 26 17:02:48 1997 From: hugunin@mit.edu (Jim Hugunin) Date: Wed, 26 Feb 1997 12:02:48 -0500 Subject: [PYTHON MATRIX-SIG] Win95 NumPy 1.0b1 (printing arrays) Message-ID: <01BC23DC.FCB0BE30@misha.lcs.mit.edu> Andrew writes: > Yes, I did type "from Numeric import *" Sorry for the obvious question then; but sometimes you need to ask. I'm also really surprised that rebooting was required after the installation. Restarting PythonWin is sometimes needed, but I've never had to reboot (and I install this stuff rather frequently ;-) > _After rebooting_, we no longer get the NameError, and what happens is > that the correct object is created, although arrays print out as > > array([[1, 2, 3, 4], [5, 6, 7, 8]], 'l') > > as opposed to > > 1 2 3 4 > 5 6 7 8 > > This problem does not occur with the version I built on my Ultrasparc > (Solaris 2.5.1). Every array object (every python object for that matter) has two string representations. One is considered the representation of the object "repr(a)". This is expected to be a string that when passed in to python will return create the object. The other is the printable string "str(a)" for the object. This is expected to be a nice form to print out to the user. ArrayObjects define these two representations properly (after a fair bit of discussion to educate me on what properly is). Your problem is that PythonWin has been written so that when you just type "a" and return, you get "repr(a)" rather than "str(a)". This doesn't really bother me much personally, but if you want to fix it you should either look at the PythonWin source code, or send mail to the pythonwin-sig asking for help. -Jim _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From managan@llnl.gov Wed Feb 26 17:49:39 1997 From: managan@llnl.gov (Rob Managan) Date: Wed, 26 Feb 1997 09:49:39 -0800 Subject: [PYTHON MATRIX-SIG] Installing NumPy Message-ID: I found that when I installed NumPy 1.0b1 on an SGI that python could not find the module until I set the environment variable to setenv PYTHONPATH ..../Python-1.4/NumPy/NumPy I used the instructions to build NumPy in the Python source tree. However, the instructions only mention setting an environment variable when you build it as a clean extension. Is this case unusual or do the instructions need updating? Or more to the point; what should be in the PYTHONPATH environment variable and what is it used for? *-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*- Rob Managan mailto://managan@llnl.gov LLNL ph: 510-423-0903 P.O. Box 808, L-183 FAX: 510-423-5804 Livermore, CA 94551-0808 _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From hinsen@ibs.ibs.fr Wed Feb 26 18:50:27 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Wed, 26 Feb 1997 19:50:27 +0100 Subject: [PYTHON MATRIX-SIG] Installing NumPy In-Reply-To: (message from Rob Managan on Wed, 26 Feb 1997 09:49:39 -0800) Message-ID: <199702261850.TAA31112@lmspc2.ibs.fr> > I used the instructions to build NumPy in the Python source tree. However, > the instructions only mention setting an environment variable when you > build it as a clean extension. > > Is this case unusual or do the instructions need updating? Yes. See my updated instructions for details ;-) > Or more to the point; what should be in the PYTHONPATH environment variable > and what is it used for? Python looks for modules in all directories that are listed in sys.path. This variable is initialized to the value of PYTHONPATH followed by the list of directories precompiled into the interpreter. The idea is that the latter should contain everything needed for the standard installation, and PYTHONPATH the user-specific additions. But of course the borderline is not entirely clear. In fact, I use the "source tree" installation method mostly because I want the NumPy path to be built-in, since otherwise users without PYTHONPATH couldn't use it. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen@ibs.ibs.fr Laboratoire de Dynamique Moleculaire | Tel.: +33-4.76.88.99.28 Institut de Biologie Structurale | Fax: +33-4.76.88.54.94 41, av. des Martyrs | Deutsch/Esperanto/English/ 38027 Grenoble Cedex 1, France | Nederlands/Francais ------------------------------------------------------------------------------- _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From pas@xis.xerox.com Wed Feb 26 19:33:56 1997 From: pas@xis.xerox.com (Perry A. Stoll) Date: Wed, 26 Feb 1997 11:33:56 PST Subject: [PYTHON MATRIX-SIG] Win95 NumPy 1.0b1 (printing arrays) In-Reply-To: <01BC23DC.FCB0BE30@misha.lcs.mit.edu> Message-ID: <199702261934.OAA28684@fantod.xis.xerox.com> On 26 Feb, Jim Hugunin wrote: > [accurate description of repr/str snipped] > Your problem is that PythonWin has been written so that when you just type > "a" and return, you get "repr(a)" rather than "str(a)". This doesn't > really bother me much personally, but if you want to fix it you should > either look at the PythonWin source code, or send mail to the pythonwin-sig > asking for help. I don't think it's only PythonWin! On SunOS I get: jade{pas} python Python 1.4 (Jan 22 1997) [GCC 2.7.0] Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> class foo: ... def __repr__(self): return 'repr called' ... def __str__(self): return 'str called' ... >>> f = foo() >>> f repr called >>> print f str called >>> -Perry _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From amullhau@ix.netcom.com Thu Feb 27 04:44:31 1997 From: amullhau@ix.netcom.com (Andrew P. Mullhaupt) Date: Wed, 26 Feb 1997 23:44:31 -0500 Subject: [PYTHON MATRIX-SIG] Win95 NumPy 1.0b1 (printing arrays) References: <199702261934.OAA28684@fantod.xis.xerox.com> Message-ID: <3315112F.1F26@ix.netcom.com> Perry A. Stoll wrote: > > On 26 Feb, Jim Hugunin wrote: > > > [accurate description of repr/str snipped] > > I don't think it's only PythonWin! On SunOS I get: Well, you can't sell me much enthusiasm for choosing repr/str when neither one is worth a damn for functions. If we have def f() : return 1 then it seems that repr(f) ought to be 'def f() : return 1' and not '' which, no matter how many times you type it in is not going to get you your f back. Later, Andrew Mullhaupt _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From hugunin@mit.edu Thu Feb 27 20:30:52 1997 From: hugunin@mit.edu (Jim Hugunin) Date: Thu, 27 Feb 1997 15:30:52 -0500 Subject: [PYTHON MATRIX-SIG] The difference between repr and str, and printing arrays Message-ID: <9702272031.AA01122@goldilocks> I think I just fixed a bug in the way that PythonWin prints out objects in its interpreter. The cross-posting is to make sure I not instead confused about the "proper" way for things to work. Here's the issue (this uses the Numeric extensions to python, but should be easy enough to follow for anyone interested in repr's and str's). Under PythonWin's interpreter I do the following: >>> from Numeric import * >>> a = array([1,2,3]) >>> a array([1, 2, 3], 'l') >>> repr(a) "array([1, 2, 3], 'l')" >>> str(a) '1 2 3' Notice that when I just type "a", I'm getting its "repr", rather than the printable string version (which is what I want). Under most other interpreters (DOS python for example) I get: >>> from Numeric import * >>> a = array([1,2,3]) >>> a 1 2 3 >>> repr(a) "array([1, 2, 3], 'l')" >>> str(a) '1 2 3' This is the behavior I'd hoped for (and designed the repr/str conventions of NumPy around). The discrepancy is based on the fact that PythonWin prints out the repr(eval(command)) instead of either the str(eval(command)) or just eval(command) when something is typed to it's interactive prompt. I can fix PythonWin by changing line 317 of interact.py to read "print ret" or "print str(ret)" instead of "print repr(ret)". When I fix it, I get the following: >>> from Numeric import * >>> a = arange(10) >>> a 0 1 2 3 4 5 6 7 8 9 >>> repr(a) array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 'l') >>> str(a) 0 1 2 3 4 5 6 7 8 9 Notice that the arrays are now printing as I would wish, but that the quotes have been removed from around the strings in the results. I happen to like this appearence in general, but I wanted to understand two things: 1) Why does there not seem to be a simple way to get both strings and arrays to print out the way they do in most command-line interpreters? 2) Should this fix be applied to PythonWin? Does it do the right thing, and would it break anything? Thanks for any comments - Jim _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From hugunin@mit.edu Fri Feb 28 19:38:06 1997 From: hugunin@mit.edu (Jim Hugunin) Date: Fri, 28 Feb 1997 14:38:06 -0500 Subject: [PYTHON MATRIX-SIG] Printing arrays and repr vs. str Message-ID: <01BC2585.032B78F0@misha.lcs.mit.edu> PythonWin has just highlighted a critical flaw in the design of array printing for NumPy. To explain: For C objects, there are three methods related to the string representation of an array. One returns the str(a), one returns the repr(a), and the third one is used to print out the array directly. Under the current design, str(a) and repr(a) both behave "properly" for python's design. Unfortunately, the print method uses the str(a) representation, which according to Guido is not the correct way to display python objects (and if anybody should know it's Guido ;-). The interesting fact is that this "bug" in the print method has led to the behavior that almost all users of NumPy seem to want in their interactive work with arrays. I am at a total loss as to how to fix this. The right thing to do is to change the behavior of the print method to use the repr version of an array. This will however make it much less enjoyable to work with arrays in an interpreter. Not fixing the bug in the print method though will make NumPy inconsistent with the rest of python objects, and lead to inconsistent behavior as observed in PythonWin recently. Does anybody have any good suggestions on this one? -Jim _______________ 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 Feb 28 19:57:32 1997 From: guido@CNRI.Reston.Va.US (Guido van Rossum) Date: Fri, 28 Feb 1997 14:57:32 -0500 Subject: [PYTHON MATRIX-SIG] Re: Printing arrays and repr vs. str In-Reply-To: Your message of "Fri, 28 Feb 1997 14:38:06 EST." <01BC2585.032B78F0@misha.lcs.mit.edu> References: <01BC2585.032B78F0@misha.lcs.mit.edu> Message-ID: <199702281957.OAA01885@monty> > Under the current design, str(a) and repr(a) both behave "properly" for > python's design. Unfortunately, the print method uses the str(a) > representation, which according to Guido is not the correct way to display > python objects (and if anybody should know it's Guido ;-). I'm sorry that it's so complicated, but this is still not quite right. (I had to browse the sources myself, ehm.) When an object is being "printed" to a "real file", its print method is invoked with a flag. The flag can be 0 or Py_PRINT_RAW. When it is 0, you are supposed to emulate repr(); when it is Py_PRINT_RAW, you are supposed to emulate str(). For some details, see print_object() in Objects/object.c. (Actually, it's a word of flag bits.) When an object is being "printed" to something that only emulates a file, Python calls repr() or str() directly. This also happens when the object does not have a print method. The print statement uses Py_PRINT_RAW. Expressions entered at the >>> prompt use a 0 flag. > Does anybody have any good suggestions on this one? Have a user preference flag that determines whether repr() should behave like str()? Set it to on by default when Python is used interactively. --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 hugunin@mit.edu Thu Feb 27 20:30:52 1997 From: hugunin@mit.edu (Jim Hugunin) Date: Thu, 27 Feb 1997 15:30:52 -0500 Subject: [PYTHON MATRIX-SIG] The difference between repr and str, and printing arrays Message-ID: <9702272031.AA01122@goldilocks> I think I just fixed a bug in the way that PythonWin prints out objects in its interpreter. The cross-posting is to make sure I not instead confused about the "proper" way for things to work. Here's the issue (this uses the Numeric extensions to python, but should be easy enough to follow for anyone interested in repr's and str's). Under PythonWin's interpreter I do the following: >>> from Numeric import * >>> a = array([1,2,3]) >>> a array([1, 2, 3], 'l') >>> repr(a) "array([1, 2, 3], 'l')" >>> str(a) '1 2 3' Notice that when I just type "a", I'm getting its "repr", rather than the printable string version (which is what I want). Under most other interpreters (DOS python for example) I get: >>> from Numeric import * >>> a = array([1,2,3]) >>> a 1 2 3 >>> repr(a) "array([1, 2, 3], 'l')" >>> str(a) '1 2 3' This is the behavior I'd hoped for (and designed the repr/str conventions of NumPy around). The discrepancy is based on the fact that PythonWin prints out the repr(eval(command)) instead of either the str(eval(command)) or just eval(command) when something is typed to it's interactive prompt. I can fix PythonWin by changing line 317 of interact.py to read "print ret" or "print str(ret)" instead of "print repr(ret)". When I fix it, I get the following: >>> from Numeric import * >>> a = arange(10) >>> a 0 1 2 3 4 5 6 7 8 9 >>> repr(a) array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 'l') >>> str(a) 0 1 2 3 4 5 6 7 8 9 Notice that the arrays are now printing as I would wish, but that the quotes have been removed from around the strings in the results. I happen to like this appearence in general, but I wanted to understand two things: 1) Why does there not seem to be a simple way to get both strings and arrays to print out the way they do in most command-line interpreters? 2) Should this fix be applied to PythonWin? Does it do the right thing, and would it break anything? Thanks for any comments - Jim _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________