From djc@lct.com Tue Jan 7 23:07:02 1997 From: djc@lct.com (Duncan Child) Date: Tue, 7 Jan 97 17:07:02 CST Subject: [PYTHON MATRIX-SIG] Handling null data points Message-ID: <9701072307.AA06247@ lct.com> Hello, This question is best illustrated with an example: I have two numeric arrays called A and B containing some real data. Missing data has been replaced with a constant 'null' value of 100 A = ( 20 10 100 6 ) B = ( 100 1 2 1 ) Now if I use Python to calculate A divided by B: C = ( 0.2 10 50 6 ) But when A or B is null I would like the answer to be null: C = ( 100 10 100 6 ) You could loop through the elements of C and check the corresponding elements in A and B are valid and otherwise set C to null as well. But to use Python as the macro language in our data processing s/w the users will need to be able to just type C = A + B and let the program take care of null values for them. What would it take to overload the basic maths functions in Python so that they can handle null data values? Any other suggestions gratefully accepted. Thanks 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 Wed Jan 8 09:23:48 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Wed, 8 Jan 1997 10:23:48 +0100 Subject: [PYTHON MATRIX-SIG] Handling null data points In-Reply-To: <9701072307.AA06247@ lct.com> (djc@lct.com) Message-ID: <199701080923.KAA05109@lmspc2.ibs.fr> > I have two numeric arrays called A and B containing some real data. > Missing data has been replaced with a constant 'null' value of 100 > > A = ( 20 10 100 6 ) > B = ( 100 1 2 1 ) > > Now if I use Python to calculate A divided by B: > > C = ( 0.2 10 50 6 ) > > But when A or B is null I would like the answer to be null: > > C = ( 100 10 100 6 ) > The cleanest solution to your problem would be to define a new data type, "number with special null value", and define all the arithmetic operations on it. You could even do that in Python, or if speed matters as a C extension. But even with a C extension you would not get the full speed of array operations, since your arrays would be of "general object" type. -- ------------------------------------------------------------------------------- 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 Wed Jan 8 09:23:48 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Wed, 8 Jan 1997 10:23:48 +0100 Subject: [PYTHON MATRIX-SIG] Handling null data points In-Reply-To: <9701072307.AA06247@ lct.com> (djc@lct.com) Message-ID: <199701080923.KAA05109@lmspc2.ibs.fr> > I have two numeric arrays called A and B containing some real data. > Missing data has been replaced with a constant 'null' value of 100 > > A = ( 20 10 100 6 ) > B = ( 100 1 2 1 ) > > Now if I use Python to calculate A divided by B: > > C = ( 0.2 10 50 6 ) > > But when A or B is null I would like the answer to be null: > > C = ( 100 10 100 6 ) > The cleanest solution to your problem would be to define a new data type, "number with special null value", and define all the arithmetic operations on it. You could even do that in Python, or if speed matters as a C extension. But even with a C extension you would not get the full speed of array operations, since your arrays would be of "general object" type. -- ------------------------------------------------------------------------------- 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 jody@sccsi.com Wed Jan 8 11:43:07 1997 From: jody@sccsi.com (Jody Winston) Date: Wed, 8 Jan 1997 05:43:07 -0600 Subject: [PYTHON MATRIX-SIG] Handling null data points In-Reply-To: <199701080923.KAA05109@lmspc2.ibs.fr> (message from Konrad Hinsen on Wed, 8 Jan 1997 10:23:48 +0100) Message-ID: <199701081143.FAA11234@friday.sccsi.com> > The cleanest solution to your problem would be to define a new > data type, "number with special null value", and define all > the arithmetic operations on it. You could even do that in Python, > or if speed matters as a C extension. But even with a C extension > you would not get the full speed of array operations, since your > arrays would be of "general object" type. A neat trick for the C code is to use NAN (Not A Number) for the missing value and set up a signal handler that is invoked when the NANs are used. During the signal handler, you then can decide what result you want to return the to proceedure that invoked the handler. On many machines, this is much faster than doing the following code: if a == MISSING or b == MISSING: return MISSING for every item in the array. Jody ================= MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org ================= From jim.fulton@digicool.com Wed Jan 8 12:29:13 1997 From: jim.fulton@digicool.com (Jim Fulton) Date: Wed, 08 Jan 1997 07:29:13 -0500 Subject: [PYTHON MATRIX-SIG] Handling null data points References: <199701080923.KAA05109@lmspc2.ibs.fr> Message-ID: <32D39319.3FD7@digicool.com> Konrad Hinsen wrote: > > > I have two numeric arrays called A and B containing some real data. > > Missing data has been replaced with a constant 'null' value of 100 > > > > A = ( 20 10 100 6 ) > > B = ( 100 1 2 1 ) > > > > Now if I use Python to calculate A divided by B: > > > > C = ( 0.2 10 50 6 ) > > > > But when A or B is null I would like the answer to be null: > > > > C = ( 100 10 100 6 ) > > > > The cleanest solution to your problem would be to define a new > data type, "number with special null value", and define all > the arithmetic operations on it. You could even do that in Python, > or if speed matters as a C extension. But even with a C extension > you would not get the full speed of array operations, since your > arrays would be of "general object" type. The notion of a "missing value" is very important for data analysis. I implemented such a type at USGS for use in database interfaces. Unfortunately, this was never released and I haven't gotten around to reimplementing it, although the implementation was close to trivial. I think this would be very valuable. If people are interested, I'd be willing to release an implementation. I think it would also be valuable to consider supporting some special floating-point value (e.g. NAN) for use in floating-point arrays. This special value would be converted to/from the special "missing value" object when accssed in Python. -- Jim Fulton Digital Creations jim@digicool.com 540.371.6909 ## Python is my favorite language ## ## http://www.python.org/ ## ================= 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 Jan 8 12:37:17 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Wed, 8 Jan 1997 13:37:17 +0100 Subject: [PYTHON MATRIX-SIG] Handling null data points In-Reply-To: <199701081143.FAA11234@friday.sccsi.com> (message from Jody Winston on Wed, 8 Jan 1997 05:43:07 -0600) Message-ID: <199701081237.NAA05758@lmspc2.ibs.fr> > A neat trick for the C code is to use NAN (Not A Number) for the > missing value and set up a signal handler that is invoked when the > NANs are used. During the signal handler, you then can decide what But this can get messy if several programs/libraries try to use the same trick. I wouldn't use it with Python. -- ------------------------------------------------------------------------------- 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 djc@lct.com Wed Jan 8 16:44:00 1997 From: djc@lct.com (Duncan Child) Date: Wed, 8 Jan 97 10:44:00 CST Subject: [PYTHON MATRIX-SIG] Handling null data points Message-ID: <9701081644.AA11027@ lct.com> Thanks for the suggestions. I am not sure that my previous post made it clear that I was talking about null data values in the Numerical Extension Python array. I have to use the Numeric arrays because I have so much data to work with. Still, if there is a more general solution that can also be applied outside the Numeric Extension that would be even better. > The notion of a "missing value" is very important for data analysis. > I implemented such a type at USGS for use in database interfaces. > Unfortunately, this was never released and I haven't gotten around > to reimplementing it, although the implementation was close to > trivial. I think this would be very valuable. If people are > interested, I'd be willing to release an implementation. Yes please. > I think it would also be valuable to consider supporting some > special floating-point value (e.g. NAN) for use in floating-point > arrays. This special value would be converted to/from the special > "missing value" object when accssed in Python. NaN sounds interesting - at the moment I just use 1e20. This works fine for me as I only have to handle vectors of floats but it would be nice to have a solution that would be applicable to other data types. Thanks 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 Wed Jan 8 18:08:57 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Wed, 8 Jan 1997 19:08:57 +0100 Subject: [PYTHON MATRIX-SIG] Handling null data points In-Reply-To: <9701081644.AA11027@ lct.com> (djc@lct.com) Message-ID: <199701081808.TAA07334@lmspc2.ibs.fr> > NaN sounds interesting - at the moment I just use 1e20. This works fine > for me as I only have to handle vectors of floats but it would be nice > to have a solution that would be applicable to other data types. NaN is part of the IEEE float format specification, so it wouldn't be available for anything but floats. There's also infinity (positive and negative) as a special value. But it is somewhat risky to use them as "no data" identifiers because some functions return them as error indicators (e.g. sqrt(-1) is NaN). You would never know whether a certain data item is unknown or the result of an undefined operation. -- ------------------------------------------------------------------------------- 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 jim.fulton@digicool.com Wed Jan 8 18:46:17 1997 From: jim.fulton@digicool.com (Jim Fulton) Date: Wed, 08 Jan 1997 13:46:17 -0500 Subject: [PYTHON MATRIX-SIG] Handling null data points References: <199701081808.TAA07334@lmspc2.ibs.fr> Message-ID: <32D3EB79.62A2@digicool.com> Konrad Hinsen wrote: > > > NaN sounds interesting - at the moment I just use 1e20. This works fine > > for me as I only have to handle vectors of floats but it would be nice > > to have a solution that would be applicable to other data types. > > NaN is part of the IEEE float format specification, so it wouldn't be > available for anything but floats. There's also infinity (positive > and negative) as a special value. But it is somewhat risky to use > them as "no data" identifiers because some functions return them > as error indicators (e.g. sqrt(-1) is NaN). You would never know > whether a certain data item is unknown or the result of an undefined > operation. In some systems I've worked with that supported missing values, calling a function with a value outside its range yielded a missing result. So I think the example you give is reasonable. :-) This is a debatable point though. -- Jim Fulton Digital Creations jim@digicool.com 540.371.6909 ## Python is my favorite language ## ## http://www.python.org/ ## ================= 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 Jan 9 04:23:44 1997 From: amullhau@ix.netcom.com (Andrew P. Mullhaupt) Date: Wed, 08 Jan 1997 23:23:44 -0500 Subject: [PYTHON MATRIX-SIG] Handling null data points References: <199701081808.TAA07334@lmspc2.ibs.fr> Message-ID: <32D472D0.6294@ix.netcom.com> Konrad Hinsen wrote: > > NaN is part of the IEEE float format specification, so it wouldn't be > available for anything but floats. There's also infinity (positive > and negative) as a special value. But it is somewhat risky to use > them as "no data" identifiers because some functions return them > as error indicators (e.g. sqrt(-1) is NaN). You would never know > whether a certain data item is unknown or the result of an undefined > operation. This is true, as far as it goes. But in languages which provide access to the IEEE special values provides the possibility of a graceful implementation of a "NA" value. In languages where there is extensive experience with overloading "NA" and "NaN" there does not seem to be much in the way of downside, especially since properly constructed numerical routines normally do not rely on how floating exceptions are handled, except for the use of denormals. In S, where a NaN representation is used for "NA" most users would be very upset if someone tried to take away the convenienve of "NA". 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 amullhau@ix.netcom.com Thu Jan 9 04:18:08 1997 From: amullhau@ix.netcom.com (Andrew P. Mullhaupt) Date: Wed, 08 Jan 1997 23:18:08 -0500 Subject: [PYTHON MATRIX-SIG] Handling null data points References: <9701081644.AA11027@ lct.com> Message-ID: <32D47180.175D@ix.netcom.com> Duncan Child wrote: > > Thanks for the suggestions. I am not sure that my previous post made it > clear that I was talking about null data values in the Numerical Extension > Python array. I have to use the Numeric arrays because I have so much > data to work with. Still, if there is a more general solution that can also > be applied outside the Numeric Extension that would be even better. > There is. You want to use NaN values with all the floating types. The only really annoying problem is that no such value is conveniently available for integer types. It is enormously convenient to have a special value "NA" for all numeric types. The semantics are pretty obvious, (you can base them on the IEEE rules for NaN representations). A good example of what happens with "NA" is the S language. The only really weird problem is that for integers they use a value which is not quite 'MAXINT'. A good example of what happens if "NA" is not provided is given by the tons of APL code where the normal approach is a validity mask, (i.e. a boolean array parallel to an APL array which uses logical values to indicate if the corresponding value in the APL array is 'valid'). Both approaches are useful, but the "NA" approach leads to better performance and much better memory usage. Given the complete acceptance of IEEE arithmetic on all useful platforms (No, a Cray is no longer a useful platform), there is no real obstacle to implementing the "NA" approach. There is a _ton_ of experience in this direction with both approaches (almost 35 years of APL and almost 30 years of S). > NaN sounds interesting - at the moment I just use 1e20. This works fine > for me as I only have to handle vectors of floats but it would be nice > to have a solution that would be applicable to other data types. Actually, the extensive discussion leading to the authoritative IEEE arithmetic standard makes many things clear, such as why using a 'sufficiently large (small)' value is a bad idea. In the particular case of using a large, but otherwise normal value, then what happens if the data is transformed say, by taking logarithms, and then passed to another routine which then needs to know if that data is valid. log(1e20) is not 'crazy' enough when you need to play 'spot the looney'. The only really difficult aspect of implementing "NA" is what to use for integer or other types. Here, the hardware was not designed with a convenient hook for a "NA" value, so lots of arguments are likely to result. In my opinion, an "NA" value is so useful that one will eventually be provided by somebody in some form, so it is probably important for people who might have to deal with the consequences of that to think about the larger issues involved. The only thing worse than having _no_ consistent approach to "NA" is having _more than one_. 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 hinsen@ibs.ibs.fr Thu Jan 9 16:19:19 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Thu, 9 Jan 1997 17:19:19 +0100 Subject: [PYTHON MATRIX-SIG] Another netCDF interface Message-ID: <199701091619.RAA13157@lmspc2.ibs.fr> For my current major programming project I needed netCDF access, and although a netCDF interface module for Python already exists, I was not quite happy with it. I needed variable objects that behave as much as possible like arrays, because I'll use both arrays and netCDF variables interchangeably depending on size. I also needed extendable variables for output, which the existing interface does not seem to support. And I needed a quick project for the holidays anyway, so... I wrote another netCDF interface module. My module provides two new C types: netCDF files, and netCDF variables. Once created, netCDF variables support most of the indexing operations of arrays (the exception being negative strides). Attributes of files and variables end up as Python attributes. An example program that creates a demo file looks like this: ---------------------------------------------------------------------- from Numeric import * from netcdf import * file = NetCDFFile('test.nc', 'w') file.title = "Just some useless junk" file.version = 42 file.createDimension('xyz', 3) file.createDimension('n', 20) file.createDimension('t', 0) foo = file.createVariable('foo', Float, ('n', 'xyz')) foo[:,:] = 0. foo[0,:] = [42., 42., 42.] foo[:,1] = 1. foo.units = "arbitrary" print foo[0] bar = file.createVariable('bar', Int, ('t', 'n')) for i in range(10): bar[i] = i print bar.shape file.close() ---------------------------------------------------------------------- This is still work in progress, since it hasn't been tested much, error checking needs improvement, and the C API is only partly defined/implemented. What I am looking for now is people willing to test my code. All you need is Python 1.4, NumPy, and the netcdf library from Unidata. For Linux I can even supply a ready-made dynamic module. There's is also one problem that needs more attention: since file objects and variable objects contain mutual references, they will never be destroyed, thus creating a memory leak. This shouldn't be too much of a problem, since the objects are small and you are not likely to create many of them. But I will eventually take care of this. Any volunteers? -- ------------------------------------------------------------------------------- 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 ta.short@pti-us.com Mon Jan 20 13:43:02 1997 From: ta.short@pti-us.com (Tom Short) Date: Mon, 20 Jan 1997 08:43:02 -0500 (EST) Subject: [PYTHON MATRIX-SIG] Newbie questions about NumPy under PythonWin Message-ID: <3.0.1.16.19970120084237.0f0f37c8@mailhost1473> (1) I am having trouble running the numeric module under PythonWin. Typing "from Numeric import *" does not work (it says no module named numeric). I'm guessing that the PythonPath is not set right, but I can't find a way to change it under PythonWin. (2) Are there any plotting routines that work with PythonWin and NumPy? I searched the archive but got the impression that the available plotting modules (I saw GIST and PLPLOT referenced) only work under unix. TIA - Tom _______________ 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 Jan 20 15:01:46 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Mon, 20 Jan 1997 16:01:46 +0100 Subject: [PYTHON MATRIX-SIG] netCDF interface: new version Message-ID: <199701201501.QAA00365@lmspc2.ibs.fr> I have made some major enhancements to the netCDF interface module I announced a while ago. There are now four file modes, including the essential "r+" (open an existing file for input and output), and there is a reasonably complete C API plus a simple demonstration module. As far as I am concerned the C API is complete, but maybe I have overlooked something. If you want a copy, just mail me. Unfortunately local regulations don't allow me to set up a Web or FTP server, so e-mail is the only distribution form I can offer... 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 da@maigret.cog.brown.edu Mon Jan 20 15:06:19 1997 From: da@maigret.cog.brown.edu (David Ascher) Date: Mon, 20 Jan 1997 10:06:19 -0500 (EST) Subject: [PYTHON MATRIX-SIG] Newbie questions about NumPy under PythonWin In-Reply-To: <3.0.1.16.19970120084237.0f0f37c8@mailhost1473> from "Tom Short" at Jan 20, 97 08:43:02 am Message-ID: <199701201506.KAA00764@maigret> > (1) I am having trouble running the numeric module under PythonWin. Typing > "from Numeric import *" does not work (it says no module named numeric). > I'm guessing that the PythonPath is not set right, but I can't find a way > to change it under PythonWin. I'll leave it to others to help you with this one -- I forget the details. > (2) Are there any plotting routines that work with PythonWin and NumPy? I > searched the archive but got the impression that the available plotting > modules (I saw GIST and PLPLOT referenced) only work under unix. I once had a plplot driver for OpenGL working under Win95, but it was far from being the optimal solution. Hopefully a new version of plplot due out at some point will allow a better integration with Tk8, which would be nice. I don't think anyone has worked on Gist for Win32. --david _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From tismer@tismer.com Mon Jan 20 16:13:59 1997 From: tismer@tismer.com (Christian Tismer) Date: Mon, 20 Jan 1997 17:13:59 +0100 Subject: [PYTHON MATRIX-SIG] Newbie questions about NumPy under PythonWin References: <3.0.1.16.19970120084237.0f0f37c8@mailhost1473> Message-ID: <32E399C7.23FC@tismer.com> > (1) I am having trouble running the numeric module under PythonWin. Typing > "from Numeric import *" does not work (it says no module named numeric). > I'm guessing that the PythonPath is not set right, but I can't find a way > to change it under PythonWin. The NumPy version for PythonWin is AFAIK a bit outdated but working well. It relies on the ni module, at least in PythonWin b4 and b5. So try import ni, Numeric Import * does not work because you cannot import * from a package. - chris ---------------------------------------------------------------------- Christian Tismer - tismer@appliedbiometrics.com Our support pages: Got a real operating system? No? Try at least a real language: Python ---------------------------------------------------------------------- _______________ 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 Jan 20 18:20:44 1997 From: ta.short@pti-us.com (Tom Short) Date: Mon, 20 Jan 1997 13:20:44 -0500 (EST) Subject: [PYTHON MATRIX-SIG] Re: Newbie questions about NumPy under PythonWin Message-ID: <3.0.1.16.19970120132042.6f7f52cc@mailhost1473> At 05:13 PM 1/20/97 +0100, Christian Tismer wrote: >> (1) I am having trouble running the numeric module under PythonWin. Typing >> "from Numeric import *" does not work (it says no module named numeric). >> I'm guessing that the PythonPath is not set right, but I can't find a way >> to change it under PythonWin. >The NumPy version for PythonWin is AFAIK a bit outdated but working >well. What is out of date? How hard is it to update from the current NumPy sources? The NumPy web page is not very clear on what to do for the Win32 platform. >It relies on the ni module, at least in PythonWin b4 and b5. >So try import ni, Numeric >Import * does not work because you cannot import * from a package. import ni, Numeric did not work. import ni; import NumPy.Numeric did work, but this leads to some unwieldy constructs like: x = NumPy.Numeric.array([5,6,4,3,3]) Also, with this approach, I couldn't figure out how to access the MLab.py routines. - Tom _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From tismer@tismer.com Mon Jan 20 20:17:33 1997 From: tismer@tismer.com (Christian Tismer) Date: Mon, 20 Jan 1997 21:17:33 +0100 Subject: [PYTHON MATRIX-SIG] Re: Newbie questions about NumPy under PythonWin References: <3.0.1.16.19970120132042.6f7f52cc@mailhost1473> Message-ID: <32E3D2DD.4A6A@tismer.com> > >The NumPy version for PythonWin is AFAIK a bit outdated but working > >well. > > What is out of date? How hard is it to update from the current NumPy > sources? The NumPy web page is not very clear on what to do for the Win32 > platform. Mark Hammond says he is unable to support all other packages and does not include NumPy. So I had to keep with the last version which is in Python win delivery b4 and b5. b6 is without, and not so stable by now. If you have the MS c compiler which Mark uses, you can try to build it. I don't know if this is difficult, at least it is a welcome contribution ;^) > > >It relies on the ni module, at least in PythonWin b4 and b5. > >So try import ni, Numeric > >Import * does not work because you cannot import * from a package. > > import ni, Numeric did not work. Look at your PythonPath, it should contain NumPy by default. If not, then you had something wrong at installation time. The registry contains a key for every package that gets its own path. You might watch it with regedit: HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\1.4.0\PythonPath It must contain a key "Numeric" and a standard value of e.g. "E:\Python\NumPy" Look for the others there and do it analoguous. If you don't have registry entries at all, then you have a totally outdated Pythonwin. _do_ _not_ use any binaries from the Pysthon CD-s, they are definately out of date. > import ni; import NumPy.Numeric did work, but this leads to some unwieldy > constructs like: > > x = NumPy.Numeric.array([5,6,4,3,3]) Despite the above, it would not hurt to say Numeric = NumPy.Numeric x = Numeric.array([1,2,3]) > > Also, with this approach, I couldn't figure out how to access the MLab.py > routines. This one works: import ni, Numeric from Numeric import FFT The same does not work for (this version of) MLab, because it falsely includes "from Numeric import *" which is again not ok for "ni". You might change that or look for another version. I think this was in an early state. ok? - chris _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From andy@CCMSD.chem.uga.edu Thu Jan 23 18:13:52 1997 From: andy@CCMSD.chem.uga.edu (Andy Dustman) Date: Thu, 23 Jan 1997 13:13:52 -0500 (EST) Subject: [PYTHON MATRIX-SIG] Strange problem importing Numeric Message-ID: I am setting up NumPy1.06a under IRIX 5.3 and odd things are happening. Python 1.4 (Oct 28 1996) [C] Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> import Numeric Traceback (innermost last): File "", line 1, in ? File "/usr/local/lib/python1.4/Numeric.py", line 4, in ? import multiarray ImportError: 13614:python: rld: Fatal Error: cannot map soname 'libnumpymodule.so' using any of the filenames /usr/lib/libnumpymodule.so:/lib/libnumpymodule.so:/lib/cmplrs/cc/libnumpymodule.so:/usr/lib/cmplrs/cc/libnumpymodule.so: -- either the file does not exist or the file is not mappable (with reason indicated in previous msg) >>> import sys >>> sys.path ['', '', '/usr/local/lib/python1.4', '/usr/local/lib/python1.4/sharedmodules', '', '/usr/local/lib/python1.4', '/usr/local/lib/python1.4/test', '/usr/local/lib/python1.4/irix5', '/usr/local/lib/python1.4/sharedmodules'] >>> Note the strange path it uses when it tries to map libnumpymodule.so, and what sys.path says. Similar things happen if I first import ni. libnumpymodule.so is actually in /usr/local/lib/python1.4/sharedmodules. (I just realized I have to change the default path, though, to also add /usr/local/lib/python1.4/NumPy, since to get this to go this far I had to copy those files directly into Lib. I'm not sure how to go about this, though...) -- Andy Dustman / Computational Center for Molecular Structure and Design / UGA You can have my PGP public key by sending mail with subject "send file key". You can have my PGP secret key when you pry it out of my cold, dead neurons. http://charon.chem.uga.edu/~andy mailto:andy@CCMSD.chem.uga.edu <}+++< _______________ 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 Jan 23 18:58:59 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Thu, 23 Jan 1997 19:58:59 +0100 Subject: [PYTHON MATRIX-SIG] Strange problem importing Numeric In-Reply-To: (message from Andy Dustman on Thu, 23 Jan 1997 13:13:52 -0500 (EST)) Message-ID: <199701231858.TAA13366@lmspc2.ibs.fr> > Note the strange path it uses when it tries to map libnumpymodule.so, and > what sys.path says. Similar things happen if I first import ni. You can avoid all problems related to libnumpy by using the first installation method (i.e. in the Python source code tree). > (I just realized I have to change the default path, though, to also add > /usr/local/lib/python1.4/NumPy, since to get this to go this far I had to > copy those files directly into Lib. I'm not sure how to go about this, > though...) Without recompiling the interpreter, all you can do is to add the directory to PYTHONPATH. If you do use the other installation method, you can modify the default path by changing Modules/Setup. Change the line COREPYTHONPATH=$(DESTPATH)$(SITEPATH)$(TESTPATH)$(MACHDEPPATH)$(STDWINPATH)$(TKPATH) to COREPYTHONPATH=$(DESTPATH)$(SITEPATH)$(TESTPATH)$(MACHDEPPATH)$(STDWINPATH)$(TKPATH)$(NUMPYPATH) and add the line NUMPYPATH=:$(DESTLIB)/NumPy anywhere below (most reasonably close to the NumPy module definitions). -- ------------------------------------------------------------------------------- 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 andy@CCMSD.chem.uga.edu Thu Jan 23 19:56:49 1997 From: andy@CCMSD.chem.uga.edu (Andy Dustman) Date: Thu, 23 Jan 1997 14:56:49 -0500 (EST) Subject: [PYTHON MATRIX-SIG] Strange problem importing Numeric In-Reply-To: <199701231858.TAA13366@lmspc2.ibs.fr> Message-ID: On Thu, 23 Jan 1997, Konrad Hinsen wrote: > You can avoid all problems related to libnumpy by using the first > installation method (i.e. in the Python source code tree). Except I am already using the first installation method. > Without recompiling the interpreter, all you can do is to add > the directory to PYTHONPATH. If you do use the other installation > method, you can modify the default path by changing Modules/Setup. > Change the line > > COREPYTHONPATH=$(DESTPATH)$(SITEPATH)$(TESTPATH)$(MACHDEPPATH)$(STDWINPATH)$(TKPATH) > > to > > COREPYTHONPATH=$(DESTPATH)$(SITEPATH)$(TESTPATH)$(MACHDEPPATH)$(STDWINPATH)$(TKPATH)$(NUMPYPATH) > > and add the line > > NUMPYPATH=:$(DESTLIB)/NumPy > > anywhere below (most reasonably close to the NumPy module definitions). This works, but there is another problem (and solution): for "make install" to find the NumPy stuff, you have to edit the line where it says LIBSUBDIRS= stdwin tkinter test $(MACHDEPS) and change it to LIBSUBDIRS= stdwin tkinter test $(MACHDEPS) NumPy Then it correctly transfers those files. This is better, but I still get: Python 1.4 (Oct 28 1996) [C] Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> import sys >>> sys.path ['', '', '/usr/local/lib/python1.4', '/usr/local/lib/python1.4/sharedmodules', '', '/usr/local/lib/python1.4', '/usr/local/lib/python1.4/test', '/usr/local/lib/python1.4/irix5', '/usr/local/lib/python1.4/sharedmodules', '/usr/local/lib/python1.4/NumPy'] >>> import Numeric Traceback (innermost last): File "", line 1, in ? File "/usr/local/lib/python1.4/NumPy/Numeric.py", line 4, in ? import multiarray ImportError: 26248:python: rld: Fatal Error: cannot map soname 'libnumpymodule.so' using any of the filenames /usr/lib/libnumpymodule.so:/lib/libnumpymodule.so:/lib/cmplrs/cc/libnumpymodule.so:/usr/lib/cmplrs/cc/libnumpymodule.so: -- either the file does not exist or the file is not mappable (with reason indicated in previous msg) >>> ^D % ls -l /usr/local/lib/python1.4/sharedmodules/libnumpymodule.so -r-xr-xr-x 1 root sys 164700 Jan 23 12:23 -- Andy Dustman / Computational Center for Molecular Structure and Design / UGA You can have my PGP public key by sending mail with subject "send file key". You can have my PGP secret key when you pry it out of my cold, dead neurons. http://charon.chem.uga.edu/~andy mailto:andy@CCMSD.chem.uga.edu <}+++< _______________ 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 Jan 23 20:30:50 1997 From: da@maigret.cog.brown.edu (David Ascher) Date: Thu, 23 Jan 1997 15:30:50 -0500 (EST) Subject: [PYTHON MATRIX-SIG] Strange problem importing Numeric In-Reply-To: from "Andy Dustman" at Jan 23, 97 02:56:49 pm Message-ID: <199701232030.PAA08317@maigret> > Then it correctly transfers those files. This is better, but I still get: > > Python 1.4 (Oct 28 1996) [C] > Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam > >>> import sys > >>> sys.path > ['', '', '/usr/local/lib/python1.4', > '/usr/local/lib/python1.4/sharedmodules', '', '/usr/local/lib/python1.4', > '/usr/local/lib/python1.4/test', '/usr/local/lib/python1.4/irix5', > '/usr/local/lib/python1.4/sharedmodules', > '/usr/local/lib/python1.4/NumPy'] > >>> import Numeric > Traceback (innermost last): > File "", line 1, in ? > File "/usr/local/lib/python1.4/NumPy/Numeric.py", line 4, in ? > import multiarray > ImportError: 26248:python: rld: Fatal Error: cannot map soname > 'libnumpymodule.so' using any of the filenames > /usr/lib/libnumpymodule.so:/lib/libnumpymodule.so:/lib/cmplrs/cc/libnumpymodule.so:/usr/lib/cmplrs/cc/libnumpymodule.so: > -- either the file does not exist or the file is not mappable (with reason > indicated in previous msg) > >>> ^D > % ls -l /usr/local/lib/python1.4/sharedmodules/libnumpymodule.so > -r-xr-xr-x 1 root sys 164700 Jan 23 12:23 You should add /usr/local/lib/python1.4/sharedmodules to your LD_LIBRARY_PATH. --david _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From andy@CCMSD.chem.uga.edu Thu Jan 23 20:54:05 1997 From: andy@CCMSD.chem.uga.edu (Andy Dustman) Date: Thu, 23 Jan 1997 15:54:05 -0500 (EST) Subject: [PYTHON MATRIX-SIG] Strange problem importing Numeric In-Reply-To: <199701232030.PAA08317@maigret> Message-ID: On Thu, 23 Jan 1997, David Ascher wrote: > > Python 1.4 (Oct 28 1996) [C] > > Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam > > >>> import sys > > >>> sys.path > > ['', '', '/usr/local/lib/python1.4', > > '/usr/local/lib/python1.4/sharedmodules', '', '/usr/local/lib/python1.4', > > '/usr/local/lib/python1.4/test', '/usr/local/lib/python1.4/irix5', > > '/usr/local/lib/python1.4/sharedmodules', > > '/usr/local/lib/python1.4/NumPy'] > > >>> import Numeric > > Traceback (innermost last): > > File "", line 1, in ? > > File "/usr/local/lib/python1.4/NumPy/Numeric.py", line 4, in ? > > import multiarray > > ImportError: 26248:python: rld: Fatal Error: cannot map soname > > 'libnumpymodule.so' using any of the filenames > > /usr/lib/libnumpymodule.so:/lib/libnumpymodule.so:/lib/cmplrs/cc/libnumpymodule.so:/usr/lib/cmplrs/cc/libnumpymodule.so: > > -- either the file does not exist or the file is not mappable (with reason > > indicated in previous msg) > > >>> ^D > > % ls -l /usr/local/lib/python1.4/sharedmodules/libnumpymodule.so > > -r-xr-xr-x 1 root sys 164700 Jan 23 12:23 > > You should add /usr/local/lib/python1.4/sharedmodules to your > LD_LIBRARY_PATH. Okay, so this is not so much a problem with Python, but a general shared library problem. I made a symlink in /usr/lib to real library in sharedmodules and that has corrected the problem. I'll have to figure out what exactly needs to be done on SGI to change the path for shared libraries. Thanx, guys. -- Andy Dustman / Computational Center for Molecular Structure and Design / UGA You can have my PGP public key by sending mail with subject "send file key". You can have my PGP secret key when you pry it out of my cold, dead neurons. http://charon.chem.uga.edu/~andy mailto:andy@CCMSD.chem.uga.edu <}+++< _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From andy@CCMSD.chem.uga.edu Thu Jan 23 21:16:59 1997 From: andy@CCMSD.chem.uga.edu (Andy Dustman) Date: Thu, 23 Jan 1997 16:16:59 -0500 (EST) Subject: [PYTHON MATRIX-SIG] Strange problem importing Numeric In-Reply-To: <199701232030.PAA08317@maigret> Message-ID: Well it says it passes the tests in test-all.py. But, if I try either mandelbrot.py or sieve.py, I get: % python sieve.py Traceback (innermost last): File "sieve.py", line 3, in ? from Numeric.Core import * File "/usr/local/lib/python1.4/ni.py", line 306, in import_module return self.finish(m, m, tail, fromlist) File "/usr/local/lib/python1.4/ni.py", line 321, in finish m = self.get1(yname) File "/usr/local/lib/python1.4/ni.py", line 338, in get1 m = self.get(name) File "/usr/local/lib/python1.4/ni.py", line 358, in get path = sys.modules[head].__path__ AttributeError: __path__ Anyone got a shrubbery? If I just import Numeric, I get no errors. Even the html docs say to import Numeric, so are the demo programs out of date? There's no Core in Numeric, anyway, as near as I can tell from dir(Numeric) (but then, I don't understand exactly how ni works). If I change "from Numeric.Core import *" to "from Numeric import *", sieve seems to work, BTW. -- Andy Dustman / Computational Center for Molecular Structure and Design / UGA You can have my PGP public key by sending mail with subject "send file key". You can have my PGP secret key when you pry it out of my cold, dead neurons. http://charon.chem.uga.edu/~andy mailto:andy@CCMSD.chem.uga.edu <}+++< _______________ 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 Jan 23 21:40:29 1997 From: da@maigret.cog.brown.edu (David Ascher) Date: Thu, 23 Jan 1997 16:40:29 -0500 (EST) Subject: [PYTHON MATRIX-SIG] Strange problem importing Numeric In-Reply-To: from "Andy Dustman" at Jan 23, 97 04:16:59 pm Message-ID: <199701232140.QAA08880@maigret> > % python sieve.py > Traceback (innermost last): > File "sieve.py", line 3, in ? > from Numeric.Core import * > File "/usr/local/lib/python1.4/ni.py", line 306, in import_module > return self.finish(m, m, tail, fromlist) > File "/usr/local/lib/python1.4/ni.py", line 321, in finish > m = self.get1(yname) > File "/usr/local/lib/python1.4/ni.py", line 338, in get1 > m = self.get(name) > File "/usr/local/lib/python1.4/ni.py", line 358, in get > path = sys.modules[head].__path__ > AttributeError: __path__ > > Anyone got a shrubbery? If I just import Numeric, I get no errors. Even > the html docs say to import Numeric, so are the demo programs out of date? > There's no Core in Numeric, anyway, as near as I can tell from > dir(Numeric) (but then, I don't understand exactly how ni works). If I > change "from Numeric.Core import *" to "from Numeric import *", sieve > seems to work, BTW. Yah, the demos are out of date. They date from a version of Numeric which used 'ni'. _______________ 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 Thu Jan 23 21:43:02 1997 From: pas@xis.xerox.com (Perry Stoll) Date: Thu, 23 Jan 1997 13:43:02 PST Subject: [PYTHON MATRIX-SIG] Strange problem importing Numeric In-Reply-To: Message-ID: <199701232143.QAA12581@fantod.xis.xerox.com> On 23 Jan, Andy Dustman wrote: > On Thu, 23 Jan 1997, David Ascher wrote: > > Okay, so this is not so much a problem with Python, but a general shared > library problem. I made a symlink in /usr/lib to real library in > sharedmodules and that has corrected the problem. I'll have to figure out > what exactly needs to be done on SGI to change the path for shared > libraries. Thanx, guys. > Isn't there a flag (-r?) to ld on SGI to tell it to remember the directory where it found the shared library to satisfy the initial linking? FWIW, I've just installed NumPy on SunOS 4.1.3 and had a problem building it dynamically. Compilation went fine, but loading ranlib or fftpack caused python to quit: ld gave up, complaining it couldn't find _sqrt, and for fftpack ld can't find _acos. The problem goes away if I link fast_umath/umath statically. So... the math lib wasn't satisfying any references when python was being linked, and so wasn't being linked in? -Perry _______________ 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 Jan 24 09:03:28 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Fri, 24 Jan 1997 10:03:28 +0100 Subject: [PYTHON MATRIX-SIG] Strange problem importing Numeric In-Reply-To: (message from Andy Dustman on Thu, 23 Jan 1997 16:16:59 -0500 (EST)) Message-ID: <199701240903.KAA15422@lmspc2.ibs.fr> > Well it says it passes the tests in test-all.py. But, if I try either > mandelbrot.py or sieve.py, I get: > > % python sieve.py > Traceback (innermost last): > File "sieve.py", line 3, in ? > from Numeric.Core import * ^^^^^^^^^^^^ There's the proof: you are using an old version of NumPy, the experimental one with packages. You should upgrade to the latest version (1.0a6). -- ------------------------------------------------------------------------------- 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 Fri Jan 24 09:01:41 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Fri, 24 Jan 1997 10:01:41 +0100 Subject: [PYTHON MATRIX-SIG] Strange problem importing Numeric In-Reply-To: <199701232143.QAA12581@fantod.xis.xerox.com> (message from Perry Stoll on Thu, 23 Jan 1997 13:43:02 PST) Message-ID: <199701240901.KAA15414@lmspc2.ibs.fr> > FWIW, I've just installed NumPy on SunOS 4.1.3 and had a problem > building it dynamically. Compilation went fine, but loading ranlib or > fftpack caused python to quit: ld gave up, complaining it couldn't find > _sqrt, and for fftpack ld can't find _acos. The problem goes away if I > link fast_umath/umath statically. So... the math lib wasn't satisfying > any references when python was being linked, and so wasn't being linked > in? The interpreter itself doesn't need the math functions, they are only in modules like math and umath. Besides, even if they were linked with the interpreter, that doesn't mean they would be also be visible to shared libraries (details vary with operating systems). So you should always link the shared libraries themselves with -lm if they need math functions. If libm itself is a shared library (as it is on most modern systems) there is no disadvantage, since it will be loaded only once. -- ------------------------------------------------------------------------------- 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 andy@CCMSD.chem.uga.edu Fri Jan 24 14:21:19 1997 From: andy@CCMSD.chem.uga.edu (Andy Dustman) Date: Fri, 24 Jan 1997 09:21:19 -0500 (EST) Subject: [PYTHON MATRIX-SIG] Strange problem importing Numeric In-Reply-To: <199701240903.KAA15422@lmspc2.ibs.fr> Message-ID: On Fri, 24 Jan 1997, Konrad Hinsen wrote: > > from Numeric.Core import * > ^^^^^^^^^^^^ > There's the proof: you are using an old version of NumPy, the experimental > one with packages. You should upgrade to the latest version (1.0a6). It is 1.0a6, the demos just haven't been updated, apparently. -- Andy Dustman / Computational Center for Molecular Structure and Design / UGA You can have my PGP public key by sending mail with subject "send file key". You can have my PGP secret key when you pry it out of my cold, dead neurons. http://charon.chem.uga.edu/~andy mailto:andy@CCMSD.chem.uga.edu <}+++< _______________ 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 Jan 27 22:43:38 1997 From: barton@simsg1.mdc.com (Brien Barton) Date: Mon, 27 Jan 1997 14:43:38 -0800 (PST) Subject: [PYTHON MATRIX-SIG] max/min bug? Message-ID: Is the following a bug or am I just confused?? ~> python Python 1.4 (Jan 24 1997) [C] Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> from Numeric import * >>> a = reshape(arange(9),(3,3)) >>> a 0 1 2 3 4 5 6 7 8 >>> min(a) 6 7 8 >>> max(a) 0 1 2 >>> It seems that if a is a two-dimensional array, then min(a) returns the last row and max(a) returns the first row. I am using NumPy1.0a6 and I noticed that the min and max functions aren't mentioned in the doc.html file so maybe I shouldn't be using them. Any ideas? -- 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 pas@xis.xerox.com Mon Jan 27 23:36:10 1997 From: pas@xis.xerox.com (Perry Stoll) Date: Mon, 27 Jan 1997 15:36:10 PST Subject: [PYTHON MATRIX-SIG] max/min bug? In-Reply-To: Message-ID: <199701272336.SAA29254@fantod.xis.xerox.com> On 27 Jan, Brien Barton wrote: > Is the following a bug or am I just confused?? >>>> min(a) > 6 7 8 >>>> max(a) > 0 1 2 >>>> Confused about a bug? No, not quite. It's something which I'm sure is going to bite a lot of people. > It seems that if a is a two-dimensional array, then min(a) returns the last > row and max(a) returns the first row. Strange. > that the min and max functions aren't mentioned in the doc.html file so > maybe I shouldn't be using them. Are you trying to find the maximum value in a? Then try: >>> max(Numeric.ravel(a)) 8 Numeric.maximum returns an array whose entries are the maximum of it's inputs: >>> Numeric.maximum(a,4) 4 4 4 4 4 5 6 7 8 Same with min/minimum. I'll also add that there is no documentation in doc.html about the attributes of arrays that one might want to use, e.g. shape. Jim, could that get added? -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 Tue Jan 28 01:56:26 1997 From: barton@simsg1.mdc.com (Brien Barton) Date: Mon, 27 Jan 1997 17:56:26 -0800 (PST) Subject: [PYTHON MATRIX-SIG] max/min bug? In-Reply-To: <199701272336.SAA29254@fantod.xis.xerox.com> Message-ID: On Mon, 27 Jan 1997, Perry Stoll wrote: > On 27 Jan, Brien Barton wrote: > > ... talking about min and max functions on arrays in NumPy1.0a6 ... > > It seems that if a is a two-dimensional array, then min(a) returns the last > > row and max(a) returns the first row. > > Strange. Yes, but bug or feature?? > > Are you trying to find the maximum value in a? > Actually, I expected min to act like the min function in the MLab module. It turns out that minimum.reduce(a) does what I wanted, which is to find the smallest element in each column of a. The version of MLab.py in the 1.0a6 distribution doesn't work. For anyone else who finds it useful, a corrected version is listed below: -- Brien ============================== cut here ===================================== """Matlab(tm) compatibility functions. This will hopefully become a complete set of the basic functions available in matlab. The syntax is kept as close to the matlab syntax as possible. One fundamental change is that the first index in matlab varies the fastest (as in FORTRAN). That means that it will usually perform reductions over columns, whereas with this object the most natural reductions are over rows. It's perfectly possible to make this work the way it does in matlab if that's desired. """ from Numeric import * # Elementary Matrices # zeros is from matrixmodule in C # ones is from Numeric.py import RandomArray def rand(*args): """rand(d1,...,dn) returns a matrix of the given dimensions which is initialized to random number in the range [0,1). """ return RandomArray.random(args) Numeric_zeros = zeros Numeric_ones = ones def zeros(*args): return Numeric_zeros(args) def ones(*args): return Numeric_ones(args) def eye(N, M=None, k=0, typecode=None): """eye(N, M=N, k=0, typecode=None) returns a N-by-M matrix where the k-th diagonal is all ones, and everything else is zeros. """ if M == None: M = N m = equal(subtract.outer(arange(N), arange(M)), -k) if typecode != None: m = m * array(1, typecode) return m def tri(N, M=None, k=0, typecode=None): if M == None: M = N m = greater_equal(subtract.outer(arange(N), arange(M)), -k) if typecode != None: m = m * array(1, typecode) return m # Matrix manipulation def diag(v, k=0): return diagonal(v, k) def fliplr(m): return m[:, ::-1] def flipud(m): return m[::-1] # reshape(x, m, n) is not used, instead use reshape(x, (m, n)) def rot90(m, k=1): """rot90(m, k=1) rotates m clockwise in k 90 degree increments""" k = k % 4 if k == 0: return m elif k == 1: return transpose(m)[::,::-1] elif k == 2: return m[::-1,::-1] elif k == 3: return transpose(m)[::-1,::] def tril(m, k=0): return tri(m.shape[0], m.shape[1], k=k, typecode=m.typecode())*m def triu(m, k=0): return (1-tri(m.shape[0], m.shape[1], k-1, m.typecode()))*m # Data analysis # Basic operations def max(m): return maximum.reduce(m) def min(m): return minimum.reduce(m) # Actually from BASIS, but it fits in so naturally here... def ptp(m): return max(m)-min(m) def mean(m): return add.reduce(m)/len(m) # sort is done in C but is done row-wise rather than column-wise def msort(m): return transpose(sort(transpose(m))) def median(m): return msort(m)[m.shape[0]/2] def std(m): mu = mean(m) return sqrt(add.reduce(pow(m-mu,2)))/sqrt(len(m)-1) def sum(m): return add.reduce(m) def cumsum(m): return add.accumulate(m) def prod(m): return multiply.reduce(m) def cumprod(m): return multiply.accumulate(m) def trapz(y, x=None): """Integrate f using the trapezoidal rule, where y is f(x). """ if x == None: d = 1 else: d = diff(x) return sum(d * (y[1:]+y[0:-1])/2) def diff(x, n=1): """Discrete difference approximation to the derivative """ if n > 1: return diff(x[1:]-x[:-1], n-1) else: return x[1:]-x[:-1] def dot(x, y): return add.reduce(x*y) def corrcoef(x, y=None): """The correlation coefficients """ c = cov(x, y) d = diag(c) return c/sqrt(multiply.outer(d,d)) def cov(m,y=None): if y != None: m = array([m,y], m.typecode()) mu = mean(m) sum_cov = 0.0 for v in m: sum_cov = sum_cov+multiply.outer(v,v) return (sum_cov-len(m)*multiply.outer(mu,mu))/(len(m)-1) _______________ 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 Jan 28 09:01:50 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Tue, 28 Jan 1997 10:01:50 +0100 Subject: [PYTHON MATRIX-SIG] max/min bug? In-Reply-To: (message from Brien Barton on Mon, 27 Jan 1997 14:43:38 -0800 (PST)) Message-ID: <199701280901.KAA32112@lmspc2.ibs.fr> > Is the following a bug or am I just confused?? You are just confused, but you are not alone. This problem will probably bite everyone at least once. > >>> from Numeric import * > >>> a = reshape(arange(9),(3,3)) > >>> a > 0 1 2 > 3 4 5 > 6 7 8 > >>> min(a) > 6 7 8 > >>> max(a) > 0 1 2 > >>> Short answer: use minimum.reduce(a) and maximum.reduce(a) to get what you expect. Long answer: min() and max() are built-in Python functions that predate NumPy. If they are called with a single argument which is a sequence (e.g. an array), they return the smallest/largest element of that sequence. Sounds fine, but isn't: what is the smallest of three arrays? Python insists that all objects have a well-defined order relation, even if there is no "natural" one. For types/classes that don't define an order relation, the default order relation is comparison of addresses. So here's what min(a) in your example does: it extracts a[0], a[1], and a[2], each of which is a 1d array, and returns the one with the smallest address. In other words, a perfectly pointless operation, since the result is machine-dependent. With the current Python interpreter there is no way to change the behaviour of min() and max(). Hopefully this will change in a later version. -- ------------------------------------------------------------------------------- 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 jhauser@ifm.uni-kiel.de Tue Jan 28 09:13:34 1997 From: jhauser@ifm.uni-kiel.de (janko hauser) Date: Tue, 28 Jan 1997 10:13:34 +0100 Subject: [PYTHON MATRIX-SIG] Re: max/min bug Message-ID: <9701280913.AA15900@flores.ifm.uni-kiel.de> I think the MLab-functions are only a first try. I think some of them could be more generally. And I have problems with the typecodes. If I compute the mean of an integer array, the result is an integer, but this is not always the mean. On the other hand, should functions change the typecode? I have made more general min and max functions. I thinks this concept can be applied to many of the functions in MLab.py. I see one problem with the definition of axis, because at the moment axis=index_of_axis_in_shape_tuple Is it wrong to think of axis=number_of_dimension - 1 ?? Anyway, here are my attempts: (If there are mistakes, please shout loud!) def max(m,axis=0): if axis == None: return maximum.reduce(ravel(m)) else: return maximum.reduce(m,axis) def min(m,axis=0): if axis == None: return minimum.reduce(ravel(m)) else: return minimum.reduce(m,axis) def mean(m,axis=0): if axis == None: return add.reduce(ravel(m))/(multiply.reduce(m.shape)*1.) else: return add.reduce(m,axis)/(m.shape[axis]*1.) def diff(m,axis=0): l_sl=[slice(None,None,None)]*len(m.shape) u_sl=l_sl[:] l_sl[axis]=slice(1,None,1) u_sl[axis]=slice(None,-1,1) return m[l_sl]-m[u_sl] def ndiff(m,n=1,axis=0): l_sl=[slice(None,None,None)]*len(m.shape) u_sl=l_sl[:] l_sl[axis]=slice(1,None,1) u_sl[axis]=slice(None,-1,1) if n >= 1: return ndiff(m[l_sl]-m[u_sl],n-1,axis) else: return m[l_sl]-m[u_sl] _______________ 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 Jan 28 10:26:44 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Tue, 28 Jan 1997 11:26:44 +0100 Subject: [PYTHON MATRIX-SIG] Re: max/min bug In-Reply-To: <9701280913.AA15900@flores.ifm.uni-kiel.de> (message from janko hauser on Tue, 28 Jan 1997 10:13:34 +0100) Message-ID: <199701281026.LAA32398@lmspc2.ibs.fr> > Anyway, here are my attempts: > (If there are mistakes, please shout loud!) > > def max(m,axis=0): > if axis == None: > return maximum.reduce(ravel(m)) > else: > return maximum.reduce(m,axis) > > def min(m,axis=0): > if axis == None: > return minimum.reduce(ravel(m)) > else: > return minimum.reduce(m,axis) The definitions are OK (and probably quite useful), but I would strongly recommend *not* to redefine min and max, which after all are built-in Python functions. If you import these definitions plus some code that needs the built-ins, you will get nasty surprises. 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 viennet@ura1507.univ-paris13.fr Tue Jan 28 11:46:51 1997 From: viennet@ura1507.univ-paris13.fr (Emmanuel Viennet) Date: Tue, 28 Jan 1997 11:46:51 GMT Subject: [PYTHON MATRIX-SIG] take() from python sequence Message-ID: <199701281146.LAA07326@montana.univ-paris13.fr> The take() method works on arbitrary sequence object, but NOT on user defined class instances acting like sequences (ie defining __getitem__() and __len__() methods). Why this restriction ? Example: class SillySeq: def __getitem__(self, i): return i def __len__(self): return 100 myseq = SillySeq() index = arange(10) take( myseq, index ) => ValueError: invalid input sequence P.S.: the restriction is enforced by arrayobject.c/discover_depth(), but Assign_Array() seems to call __getitem__(), so the restriction does not seems necessary. -- 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 jhauser@ifm.uni-kiel.de Tue Jan 28 11:14:31 1997 From: jhauser@ifm.uni-kiel.de (janko hauser) Date: Tue, 28 Jan 1997 12:14:31 +0100 Subject: [PYTHON MATRIX-SIG] Re: max/min bug In-Reply-To: <199701281026.LAA32398@lmspc2.ibs.fr> References: <9701280913.AA15900@flores.ifm.uni-kiel.de> <199701281026.LAA32398@lmspc2.ibs.fr> Message-ID: <9701281114.AA17605@flores.ifm.uni-kiel.de> Two ways are possible, rename to mmax,mmin or ask in the function for type of m and return the appropiate result, if it is something other than an array. I think the second way is error prone, because of possible other numerical objects. Or are there better indicators than 'type()'? __Janko Konrad Hinsen writes: > > Anyway, here are my attempts: > > (If there are mistakes, please shout loud!) > > > > def max(m,axis=0): > > if axis == None: > > return maximum.reduce(ravel(m)) > > else: > > return maximum.reduce(m,axis) > > > > def min(m,axis=0): > > if axis == None: > > return minimum.reduce(ravel(m)) > > else: > > return minimum.reduce(m,axis) > > The definitions are OK (and probably quite useful), but I would > strongly recommend *not* to redefine min and max, which after all are > built-in Python functions. If you import these definitions plus some > code that needs the built-ins, you will get nasty surprises. > > 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 > _______________ _______________ 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 Jan 28 11:31:48 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Tue, 28 Jan 1997 12:31:48 +0100 Subject: [PYTHON MATRIX-SIG] Re: max/min bug In-Reply-To: <9701281114.AA17605@flores.ifm.uni-kiel.de> (message from janko hauser on Tue, 28 Jan 1997 12:14:31 +0100) Message-ID: <199701281131.MAA32635@lmspc2.ibs.fr> > Two ways are possible, rename to mmax,mmin or ask in the function for > type of m and return the appropiate result, if it is something other > than an array. I think the second way is error prone, because of > possible other numerical objects. Or are there better indicators than > 'type()'? The real question is, indicators for what? How do you want to treat min([[2.5, 6.], [0., 3.]])? It ought to work like before, of course, for compatibility, so it should compare two lists by address. On the other hand, most array functions also accept nested lists as arguments, so once you pretend that min() is an array function, you create confusion. Better use other names! 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 Zachary_Roadhouse@brown.edu Tue Jan 28 14:57:41 1997 From: Zachary_Roadhouse@brown.edu (Zachary_Roadhouse@brown.edu) Date: Tue, 28 Jan 1997 09:57:41 -0500 (EST) Subject: [PYTHON MATRIX-SIG] FW: My Python/Vtk Method Message-ID: Here is something I did a while ago on Python/Vtk integration. Hopefully this will help. -----FW: My Python/Vtk Method----- Date: Wed, 11 Dec 1996 19:55:32 -0500 (EST) From: Zachary_Roadhouse@brown.edu To: vtkusers@mr.med.ge.com Subject: My Python/Vtk Method Oh well, I need a study break. Here is a synopsis of how to use Vtk with Python. This has only been attempted on Solaris 2.5.1 using Vtk 1.2 and Mesa 2.0 (I found that it was faster than GLX on our machines) 1. Build Vtk with shared libraries. This will produce a libvtk.so. 2. Build a shared library from the tclsrc code. I added this to my Makefile in the tclsrc directory. libvtkTcl.so: ${TCL_SRC_OBJ} ${TCL_SBR_OBJ} ${TCL_XGLR_OBJ} ${TCL_OGLR_OBJ} \ ${TCL_GLR_OBJ} ${TCL_NEWS} ld -G -o libvtkTcl.so ${TCL_SRC_OBJ} ${TCL_SBR_OBJ} \ ${TCL_XGLR_OBJ} ${TCL_OGLR_OBJ} ${TCL_GLR_OBJ} ${TCL_NEWS} Do a make and then a make libvtkTcl.so. This should make the vtk binary as well and the shared library. 3. Install these two libraries somewhere along your LD_LIBRARY_PATH 4. Create a new directory in vtk distribution called Python. Copy the following files there: vtkAutoInit.o vtkTclUtil.o vtkXRenderWindowInteractor.o Create a shared library from these three files: ld -G -o libvtkTkinter.so vtkAutoInit.o vtkTclUtil.o \ vtkXRenderWindowInteractor.o -lvtkTcl -lvtk -lC You now have a library with all of Vtk's Tcl interface included. Put this library somewhere in your LD_LIBRARY_PATH. 5. Now for the python side. In tkappinit.c in Python(version)/Modules add the following lines: (at the top) extern int VTK_Init(Tcl_Interp*); (Inside Tcl_AppInit after Tcl_Init) if (VTK_Init(interp) == TCL_ERROR) return TCL_ERROR; 6. Modify the tkinter entry in Python(version)/Modules/Setup. Mine looks like this (using OpenGL, Python Imaging Library, and now Vtk) _tkinter _tkinter.c tkappinit.c togl.c tkImaging.c -DSOLARIS_BUG -DWITH_APPINIT -I/usr/openwin/include -I$(EN3_PACKAGES)/include -I$(PYEXTENSIONS)/Imaging/libIm aging -L/usr/openwin/lib -L$(EN3_PACKAGES)/lib -L$(PYEXTENSIONS)/Imaging/libImag ing -lvtkTkinter -lMesaGL -lImaging -ltk4.2 -ltcl7.6 -lXext -lXmu -lX11 The only extra libraries for vtk are vtkTkinter and MesaGL. 7. You can either install _tkinter.so in the standard Python place or copy it to the directory in which you are working with vtk so that it doesn't hog extra memory if not needed. Here is an example program for the very low level interface to tcl that this provides. Some students here are working on wrapping this interface in Python objects. None of this would be neccessary we could generate the Python interface and code automatically. I'm not versed enough in yacc/etc. to do this. Good luck -- you may have to fiddle to get it to work. import _tkinter vtk = _tkinter.create() ## create a new _tkinter widget with VTK ## create a rendering window and a renderer ## first, create the RenderMaster vtk.call('vtkRenderMaster', 'rm') ## then create a RenderWindow in which to render the object renWin = vtk.call('rm', 'MakeRenderWindow') ## now create the actual thing that will do the rendering ren = vtk.call(renWin, 'MakeRenderer') ## and now create the mouse/keyboard interactor for the RenderWindow iren = vtk.call(renWin, 'MakeRenderWindowInteractor') ## now that we have everything we need to do the rendering, we ## have to create the actual object which we want to render: a cone ## this will create a cone actor and give it geometry for rendering ## i chose vtkConeSource, but change to vtkSphereSource works, too vtk.call('vtkEarthSource', 'cone' ) ## an actor called cone ## now we decide on the resolution in which to display our actor ## not all vtk____Sources support this call, but Cone does vtk.call('cone','OutlineOff') vtk.call('vtkPolyMapper','coneMapper') ## creates a PolygonMapper ## now we need to get the information to give to the PolyMapper Info = vtk.call('cone', 'GetOutput') ## creates output from the cone vtk.call('coneMapper','SetInput', Info) ## here is the actual formal Actor vtk.call('vtkActor', 'coneActor') ## the actor needs a mapper to render it, so we give it ConeMapper vtk.call('coneActor', 'SetMapper', 'coneMapper') ## now we tell the renderer which actors to render vtk.call(ren, 'AddActors', 'coneActor') ## now we initialize the mouse interactor and keyinteractors vtk.call(iren, 'SetUserMethod', '{wm deiconify .vtkInteract}') vtk.call(iren, 'Initialize') ## we don't want a tk window to show up, so we remove it vtk.call('wm', 'withdraw', '.') ## now we make the program execute... _tkinter.mainloop() - Zack E-MAIL: Zachary_Roadhouse@brown.edu WEB: http://althor.netspace.org/~zack/ Brown University, Box 220, Providence, RI 02912 Phone: (401) 863 - 5435 -------------End of forwarding message------------------------- - Zack E-MAIL: Zachary_Roadhouse@brown.edu WEB: http://althor.netspace.org/~zack/ Brown University, Box 220, Providence, RI 02912 Phone: (401) 863 - 5435 _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From jac@gandalf.llnl.gov Tue Jan 28 15:58:40 1997 From: jac@gandalf.llnl.gov (Jim Crotinger) Date: Tue, 28 Jan 1997 07:58:40 -0800 Subject: [PYTHON MATRIX-SIG] max/min bug? In-Reply-To: <199701280901.KAA32112@lmspc2.ibs.fr> References: <199701280901.KAA32112@lmspc2.ibs.fr> Message-ID: <199701281558.HAA06979@gandalf.llnl.gov> Konrad Hinsen writes: > Short answer: use minimum.reduce(a) and maximum.reduce(a) to get what you > expect. > > Long answer: min() and max() are built-in Python functions that predate > NumPy. If they are called with a single argument which is a sequence > (e.g. an array), they return the smallest/largest element of that > sequence. Sounds fine, but isn't: what is the smallest of three arrays? > That's what I thought. This violates the principle of least astonishment and really ought to be reconsidered somehow. Either it should do what everyone (or at least most people) expects (which is to return the largest/smallest element of the multidimensional array), or it should throw an exception and complain. Jim -- ------------------------------------------------------------------------------- James A. Crotinger |Magnetic Fusion Energy Theory/Computations| I speak for me crotinger@llnl.gov |Lawrence Livermore National Laboratory |The lab does not (510) 422-0259 |P.O. Box 808, L-630; Livermore CA 94550 | And vice versa _______________ 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 Jan 28 16:43:33 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Tue, 28 Jan 1997 17:43:33 +0100 Subject: [PYTHON MATRIX-SIG] max/min bug? In-Reply-To: <199701281558.HAA06979@gandalf.llnl.gov> (message from Jim Crotinger on Tue, 28 Jan 1997 07:58:40 -0800) Message-ID: <199701281643.RAA04606@lmspc2.ibs.fr> > That's what I thought. This violates the principle of least > astonishment and really ought to be reconsidered somehow. Either it > should do what everyone (or at least most people) expects (which is to > return the largest/smallest element of the multidimensional array), > or it should throw an exception and complain. I agree, but there is no way to change the behaviour of min/max without changing the Python interpreter. The proper solution would be to allow comparisons to fail (e.g. throw an exception), which is not possible right now. Then all comparisons on arrays could be made to fail (right now they work and also compare addresses!), which would automatically take care of min and max. 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 barton@simsg1.mdc.com Tue Jan 28 18:53:57 1997 From: barton@simsg1.mdc.com (Brien Barton) Date: Tue, 28 Jan 1997 10:53:57 -0800 (PST) Subject: [PYTHON MATRIX-SIG] reduce methods Message-ID: Had an idea while trying out Janko's proposed new MLab.py functions. Right now: >>> a 3 6 2 4 9 5 >>> minimum.reduce(a) 3 6 2 >>> minimum.reduce(a,1) 2 4 In the second case, we're finding the minimum value in each row, so the result I would expect is: 2 4 In other words, I'd expect the axis that was "reduced" to change to a length of one instead of completely going away. Modifying Janko's min function to do this... def mmin(m,axis=0): if axis == None: return minimum.reduce(ravel(m)) else: new_shape = list(m.shape) new_shape[axis] = 1 return reshape(minimum.reduce(m,axis), new_shape) Opinions?? -- Brien _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From Jack.Jansen@cwi.nl Wed Jan 29 09:58:08 1997 From: Jack.Jansen@cwi.nl (Jack Jansen) Date: Wed, 29 Jan 1997 10:58:08 +0100 Subject: [PYTHON MATRIX-SIG] Re: [PYTHONMAC-SIG] Numeric Python on the Mac? In-Reply-To: Message by Anthony Wilson , Tue, 28 Jan 1997 15:53:07 -0700 , Message-ID: <9701290958.AA16061=jack@snelboot.cwi.nl> > Has anyone tried and/or succeded in porting Numeric Python on the Mac? > > If so, could send me or post the instructions on how to compile the module > and conncet to macpython. I have ported it, you can get at it through my (new) MacPython page at . This is a binary-only distribution, however, for use with PPC or CFM68K Python. If you are interested in the sources let me know and I'll make them available too. And, for all you who were wondering about PIL: yes, it's coming, probably later today. -- Jack Jansen | ++++ stop the execution of Mumia Abu-Jamal ++++ Jack.Jansen@cwi.nl | ++++ if you agree copy these lines to your sig ++++ http://www.cwi.nl/~jack | see http://www.xs4all.nl/~tank/spg-l/sigaction.htm _______________ 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 Jan 29 10:08:36 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Wed, 29 Jan 1997 11:08:36 +0100 Subject: [PYTHON MATRIX-SIG] reduce methods In-Reply-To: (message from Brien Barton on Tue, 28 Jan 1997 10:53:57 -0800 (PST)) Message-ID: <199701291008.LAA07217@lmspc2.ibs.fr> > In the second case, we're finding the minimum value in each row, so the > result I would expect is: > > 2 > 4 > > In other words, I'd expect the axis that was "reduced" to change to a length > of one instead of completely going away. Modifying Janko's min function to But this is not how reduction works in Python (the built-in function "reduce") or in any of the array languages I know. It's also not what I would expect from a plain-English description: for me, a "sum of a list of numbers" is a number, not a list of length one. 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 jhauser@ifm.uni-kiel.de Wed Jan 29 10:41:07 1997 From: jhauser@ifm.uni-kiel.de (janko hauser) Date: Wed, 29 Jan 1997 11:41:07 +0100 Subject: [PYTHON MATRIX-SIG] reduce methods In-Reply-To: References: Message-ID: <9701291041.AA24207@flores.ifm.uni-kiel.de> Yeah, I think this is the better way. But I wouldn't put this in MLab.py officially, because it is not Matlab compatible. In the long run I vote for a common file with standard definitions or to put more definitions in Numeric.py. __Janko Brien Barton writes: > Had an idea while trying out Janko's proposed new MLab.py functions. Right > now: > > >>> a > 3 6 2 > 4 9 5 > >>> minimum.reduce(a) > 3 6 2 > >>> minimum.reduce(a,1) > 2 4 > > In the second case, we're finding the minimum value in each row, so the > result I would expect is: > > 2 > 4 > > In other words, I'd expect the axis that was "reduced" to change to a length > of one instead of completely going away. Modifying Janko's min function to > do this... > > def mmin(m,axis=0): > if axis == None: > return minimum.reduce(ravel(m)) > else: > new_shape = list(m.shape) > new_shape[axis] = 1 > return reshape(minimum.reduce(m,axis), new_shape) > > Opinions?? > > -- Brien > > > _______________ > MATRIX-SIG - SIG on Matrix Math for Python > > send messages to: matrix-sig@python.org > administrivia to: matrix-sig-request@python.org > _______________ _______________ 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 Jan 29 19:01:12 1997 From: furnish@laura.llnl.gov (Geoffrey Furnish) Date: Wed, 29 Jan 1997 11:01:12 -0800 Subject: [PYTHON MATRIX-SIG] max/min bug? In-Reply-To: <199701281558.HAA06979@gandalf.llnl.gov> References: <199701280901.KAA32112@lmspc2.ibs.fr> <199701281558.HAA06979@gandalf.llnl.gov> Message-ID: <199701291904.OAA03761@python.org> Jim Crotinger writes: > Konrad Hinsen writes: > > Short answer: use minimum.reduce(a) and maximum.reduce(a) to get what you > > expect. > > > > Long answer: min() and max() are built-in Python functions that predate > > NumPy. If they are called with a single argument which is a sequence > > (e.g. an array), they return the smallest/largest element of that > > sequence. Sounds fine, but isn't: what is the smallest of three arrays? > > > > That's what I thought. This violates the principle of least > astonishment and really ought to be reconsidered somehow. Either it > should do what everyone (or at least most people) expects (which is to > return the largest/smallest element of the multidimensional array), > or it should throw an exception and complain. I agree. This non intuitive behavior of min/max in NumPy has been the source of much consternation for users here. -- 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 jhauser@ifm.uni-kiel.de Thu Jan 30 08:14:06 1997 From: jhauser@ifm.uni-kiel.de (janko hauser) Date: Thu, 30 Jan 1997 09:14:06 +0100 Subject: [PYTHON MATRIX-SIG] reduce methods In-Reply-To: <199701291008.LAA07217@lmspc2.ibs.fr> References: <199701291008.LAA07217@lmspc2.ibs.fr> Message-ID: <9701300814.AA24391@flores.ifm.uni-kiel.de> If we don't change the axis to 1 we can't 'easy' subtract the mean from a field. Old mean (no axis=1) >>> a 0 1 2 3 4 5 6 7 8 >>> a-M.mean(a) -3. -3. -3. 0. 0. 0. 3. 3. 3. >>> a-M.mean(a,1) -1. -3. -5. 2. 0. -2. 5. 3. 1. New mean (with axis=1) >>> a-M.mean(a,1) -1. 0. 1. -1. 0. 1. -1. 0. 1. And the "sum of a list of numbers" is a number. msum(a,None) => 36 Konrad Hinsen writes: > > In the second case, we're finding the minimum value in each row, so the > > result I would expect is: > > > > 2 > > 4 > > > > In other words, I'd expect the axis that was "reduced" to change to a length > > of one instead of completely going away. Modifying Janko's min function to > > But this is not how reduction works in Python (the built-in function > "reduce") or in any of the array languages I know. It's also not what > I would expect from a plain-English description: for me, a "sum of > a list of numbers" is a number, not a list of length one. > > 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 > _______________ _______________ 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 Jan 30 11:32:39 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Thu, 30 Jan 1997 12:32:39 +0100 Subject: [PYTHON MATRIX-SIG] reduce methods In-Reply-To: <9701300814.AA24391@flores.ifm.uni-kiel.de> (message from janko hauser on Thu, 30 Jan 1997 09:14:06 +0100) Message-ID: <199701301132.MAA12370@lmspc2.ibs.fr> > If we don't change the axis to 1 we can't 'easy' subtract the mean > from a field. I am not quite sure what you mean by "field" and "mean of a field". If a rank-2 array a is supposed to represent a list of vectors, then m=add.reduce(a)/len(a) will be its mean, and a-m will subtract the mean vector from each vector in a. Of course there may be other cases: if a is a matrix and you want to subtract the mean of all its elements, you need a-add.reduce(ravel(a)). Again, no explicit axis argument. You do need to specify the axis if you want to subtract the mean of all columns of a, which seems what you were after in your example. 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 jhauser@ifm.uni-kiel.de Thu Jan 30 13:11:15 1997 From: jhauser@ifm.uni-kiel.de (janko hauser) Date: Thu, 30 Jan 1997 14:11:15 +0100 Subject: [PYTHON MATRIX-SIG] reduce methods In-Reply-To: <199701301132.MAA12370@lmspc2.ibs.fr> References: <9701300814.AA24391@flores.ifm.uni-kiel.de> <199701301132.MAA12370@lmspc2.ibs.fr> Message-ID: <9701301311.AA24689@flores.ifm.uni-kiel.de> Ja, das ist wirklich unklar von mir ausgedr"uckt. Ich meine das Mittel, berechnet entlang einer Achse von dem Gesamtfeld entlang dieser Achse abziehen. Das m"ochte ich entlang jeder beliebigen Achse machen k"onnen. Und f"ur andere Achsen als m.shape[0] mu\3 ich ein reshape machen...., dachte ich bisher, aber da gibt es ja noch NewAxis. Egal was man benutzt, man mu\3 aber dann immer im Blick haben, welche Achse man ersetzen m"ochte, damit die Berechnung z.B. des Mittelwertes stimmt. Das klappt nur so sch"on, wenn man Axis=0 verwendet. Auch das Teilen mit len() klappt nur bei der nullten Achse. Wenn die Funktionen aber die reduzierte Achse mit der L"ange eins behalten, dann lassen sich solche Berechnungen ziemlich 'blind' durchf"uhren. Allerdings habe ich noch nicht den Einflu\3 auf andere Funktionen "uberpr"uft oder mir Gedanken um das Grunds"atzliche gemacht. So verkleinert diff() die L"ange der angegeben Achse um eins, da sieht das auch richtig aus. Also, ich bin mir nicht sicher, ob das alles als Standard propagiert werden soll. Auf der anderen Seite, wenn man schon add.reduce maskiert, dann kann man sich ja auch von dem grunds"atzlichen von reduce entfernen. Nochmal zu dem Netcdfmodul. Ich wei\3 das 'rw' falsch ist, aber das sollte nicht alles zum Absturz bringen. Das meinte ich damit. (Mu\3 wohl lernen mich klarer auszudr"ucken... :-)) Haben eigentlich viele nach dem Modul gefragt? Ein Sache f"allt mir noch ein. Irgendwoher wissen netcdf-programme welches die unlimitierte Dimension ist. Kann man die Information noch mit einbauen? Oder habe ich wieder etwas "ubersehen? Ich w"are auch an der neuen Version interessiert :-) Bis denn __Janko Konrad Hinsen writes: > > If we don't change the axis to 1 we can't 'easy' subtract the mean > > from a field. > > I am not quite sure what you mean by "field" and "mean of a field". > If a rank-2 array a is supposed to represent a list of vectors, > then m=add.reduce(a)/len(a) will be its mean, and a-m will subtract > the mean vector from each vector in a. > > Of course there may be other cases: if a is a matrix and you want to > subtract the mean of all its elements, you need a-add.reduce(ravel(a)). > Again, no explicit axis argument. > > You do need to specify the axis if you want to subtract the mean of > all columns of a, which seems what you were after in your example. > > 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 jhauser@ifm.uni-kiel.de Thu Jan 30 14:17:43 1997 From: jhauser@ifm.uni-kiel.de (janko hauser) Date: Thu, 30 Jan 1997 15:17:43 +0100 Subject: [PYTHON MATRIX-SIG] Sorry, wrong language choosen! Message-ID: <9701301417.AA24904@flores.ifm.uni-kiel.de> Due to some technical problems with my universal language translator and my universal person-locator there was a message to Konrad Hinsen in german on this list. Sorry for that, I will have a clooser look at the code of these two programs. :-) __Janko _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From andy@CCMSD.chem.uga.edu Thu Jan 30 17:41:31 1997 From: andy@CCMSD.chem.uga.edu (Andy Dustman) Date: Thu, 30 Jan 1997 12:41:31 -0500 (EST) Subject: [PYTHON MATRIX-SIG] Error (?) in Matrix.py (1.06a) Message-ID: imports dot from Numeric, but then uses matrixmultiply (in __mul__ and __rmul__), which produces a NameError when you try to multiply two matrices. Seems to work if you instead import matrixmultiply from Numeric. Or should __mul__ and __rmul__ use dot? -- Andy Dustman / Computational Center for Molecular Structure and Design / UGA You can have my PGP public key by sending mail with subject "send file key". You can have my PGP secret key when you pry it out of my cold, dead neurons. http://charon.chem.uga.edu/~andy mailto:andy@CCMSD.chem.uga.edu <}+++< _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________ From andy@CCMSD.chem.uga.edu Thu Jan 30 18:27:45 1997 From: andy@CCMSD.chem.uga.edu (Andy Dustman) Date: Thu, 30 Jan 1997 13:27:45 -0500 (EST) Subject: [PYTHON MATRIX-SIG] PyArray_Transpose [multiarraymodule.c] dumps core Message-ID: I was testing some of the LinearAlgebra functions and discovered that eigenvectors and eigenvalues apparently work fine for ordinary arrays, but for Matrix instances, I get a core dump (SGI IRIX 5.3, R4400). I did some tracing around and it appears to happen in PyArray_Transpose when it does a Py_XDECREF. Note: If I try tracing with pdb, it dumps core immediately before I get any output. Matrix is a subclass of array, is it not? Anyway, I don't know enough about how the Python-C interface works to even begin to debug this, but I suspect a reference count problem. Hopefully this is of some use to someone. % python Python 1.4 (Oct 28 1996) [C] Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> from LinearAlgebra import eigenvalues >>> from Numeric import array >>> a=array([[1,2,3],[4,5,6],[7,8,9]]) >>> a.shape (3, 3) >>> u=eigenvalues(a) >>> u 1.61168440e+01 -1.11684397e+00 -1.26888098e-15 >>> from LinearAlgebra import eigenvectors >>> u,v=eigenvectors(a) >>> u,v ( 1.61168440e+01 -1.11684397e+00 -1.26888098e-15, 0.23197069 0.52532209 0.8186735 0.78583024 0.08675134 -0.61232756 0.40824829 -0.81649658 0.40824829) >>> from Matrix import Matrix >>> b=matrix([[1,2,3],[4,5,6],[7,8,9]]) Traceback (innermost last): File "", line 1, in ? NameError: matrix >>> b=Matrix([[1,2,3],[4,5,6],[7,8,9]]) >>> b.shape (3, 3) >>> u=eigenvalues(b) Bus error (core dumped) % dbx /usr/local/bin/python core dbx version 3.19 Nov 3 1994 19:59:46 Core from signal SIGBUS: Bus error (dbx) dump PyArray_Transpose(0x1002cc90, 0x1002a5f8, 0x2, 0x1b) ["./../NumPy/multiarraymodule.c":153, 0x5fc91f98] (dbx) list >* 153 Py_XDECREF(ret); 154 if (permutation != NULL) free(permutation); 155 PyArray_Free(op, (char *)axes); 156 return NULL; 157 } 158 159 extern PyObject *PyArray_Repeat(PyObject *aop, PyObject *op, int axis) { 160 int *counts; 161 int n, n_outer, i, j, k, chunk, total, tmp; 162 PyArrayObject *ret, *ap; (dbx) quit -- Andy Dustman / Computational Center for Molecular Structure and Design / UGA You can have my PGP public key by sending mail with subject "send file key". You can have my PGP secret key when you pry it out of my cold, dead neurons. http://charon.chem.uga.edu/~andy mailto:andy@CCMSD.chem.uga.edu <}+++< _______________ 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 Thu Jan 30 20:36:52 1997 From: barton@simsg1.mdc.com (Brien Barton) Date: Thu, 30 Jan 1997 12:36:52 -0800 (PST) Subject: [PYTHON MATRIX-SIG] reduce methods In-Reply-To: <199701301132.MAA12370@lmspc2.ibs.fr> Message-ID: On Thu, 30 Jan 1997, Konrad Hinsen wrote: > > If we don't change the axis to 1 we can't 'easy' subtract the mean > > from a field. ..snip.. > > You do need to specify the axis if you want to subtract the mean of > all columns of a, which seems what you were after in your example. I think Janko was trying to support my assertion that the mean (or max or min) of a 2-dimensional array with axis set to 1 should be a column vector. If array A isn't a square matrix and you try to do... >>> A - mean(A, axis=1) You'll get a "ValueError: frames are not aligned" message. For example: >>> def mmean(a,axis=0): ... return add.reduce(a,axis)/float(a.shape[axis]) ... >>> A 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. >>> A - mmean(A) <--- this works as expected -4. -4. -4. -4. 0. 0. 0. 0. 4. 4. 4. 4. >>> A - mmean(A,1) <--- this doesn't work at all! Traceback (innermost last): File "", line 1, in ? ValueError: frames are not aligned >>> A - reshape(mmean(A,1),(3,1)) <-- have to "fix" the shape to make it work -1.5 -0.5 0.5 1.5 -1.5 -0.5 0.5 1.5 -1.5 -0.5 0.5 1.5 -- Brien _______________ 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 Jan 31 08:42:29 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Fri, 31 Jan 1997 09:42:29 +0100 Subject: [PYTHON MATRIX-SIG] PyArray_Transpose [multiarraymodule.c] dumps core In-Reply-To: (message from Andy Dustman on Thu, 30 Jan 1997 13:27:45 -0500 (EST)) Message-ID: <199701310842.JAA20544@lmspc2.ibs.fr> > I was testing some of the LinearAlgebra functions and discovered that > eigenvectors and eigenvalues apparently work fine for ordinary arrays, but > for Matrix instances, I get a core dump (SGI IRIX 5.3, R4400). I did some I doubt that the Matrix class has even been tested intensively... > before I get any output. Matrix is a subclass of array, is it not? No. Array is implemented as an extension type, and such types can't be subclassed. Matrix is an ordinary Python class that uses an array to store its data. -- ------------------------------------------------------------------------------- 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 Fri Jan 31 08:55:58 1997 From: hinsen@ibs.ibs.fr (Konrad Hinsen) Date: Fri, 31 Jan 1997 09:55:58 +0100 Subject: [PYTHON MATRIX-SIG] reduce methods In-Reply-To: (message from Brien Barton on Thu, 30 Jan 1997 12:36:52 -0800 (PST)) Message-ID: <199701310855.JAA20598@lmspc2.ibs.fr> > I think Janko was trying to support my assertion that the mean (or max or > min) of a 2-dimensional array with axis set to 1 should be a column vector. There's the problem for people used to Matlab: There are no "row vectors" and "column vectors" in the Python array system. Arrays can have any rank, and vectors have rank 1. Matlab treats everything as a matrix (rank 2), with row and column vectors being just special kinds of matrices. Personally I have always found the MatLab way of doing things unnecessarily complicated, but of course you may disagree ;-) If there is sufficient interest in having Python equivalents of the Matlab approach, my suggestion is to define such operations on the class Matrix, and not to mix it up with the standard array operations. -- ------------------------------------------------------------------------------- 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 barton@simsg1.mdc.com Fri Jan 31 16:58:29 1997 From: barton@simsg1.mdc.com (Brien Barton) Date: Fri, 31 Jan 1997 08:58:29 -0800 (PST) Subject: [PYTHON MATRIX-SIG] reduce methods In-Reply-To: <199701310855.JAA20598@lmspc2.ibs.fr> Message-ID: On Fri, 31 Jan 1997, Konrad Hinsen wrote: > Personally I have always found the MatLab way of doing things > unnecessarily complicated, but of course you may disagree ;-) > If there is sufficient interest in having Python equivalents > of the Matlab approach, my suggestion is to define such operations > on the class Matrix, and not to mix it up with the standard array > operations. I agree. This thread developed from ideas about improving the MLab module, which is where Matlab-like operations should go. -- 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 hugunin@mit.edu Fri Jan 31 19:00:43 1997 From: hugunin@mit.edu (Jim Hugunin) Date: Fri, 31 Jan 1997 14:00:43 -0500 Subject: [PYTHON MATRIX-SIG] mean, add.reduce, and MLab.py Message-ID: <01BC0F7F.2698C2A0@misha.lcs.mit.edu> 1) MLab.py should not be considered part of NumPy. It was mainly written for me to explore how easily the functionality of matlab could be accomplished with NumPy, not as something I expected people to generally use. There are a number of differences in conventions as to how axes are treated in NumPy and matlab that makes this project in some ways a bad idea. There should however be a set of useful function like those provided in MLab.py. Unfortunately at the moment I'm more concerned with putting a beta-release of the core system together than in designing this useful functions module. 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...) -Jim _______________ MATRIX-SIG - SIG on Matrix Math for Python send messages to: matrix-sig@python.org administrivia to: matrix-sig-request@python.org _______________