From histed at MIT.EDU Wed Aug 7 17:02:18 2002 From: histed at MIT.EDU (Mark Histed) Date: Wed Aug 7 17:02:18 2002 Subject: [Numpy-discussion] more functions for MLab.py: find, unique, union, intersect, etc. Message-ID: <200208072353.TAA03451@melbourne-city-street.mit.edu> I've written some glue functions along the lines of what's in MLab.py: find unique union intersect setdiff setxor Quick questions: * any opinions on the algorithms used? * are these worth adding to MLab.py? If so, do I need to provide documentation updates? I can send this as a patch to MLab.py too. * Does anyone have opinions on what to do about the optional outputs from matlab functions? Is it worth trying to provide index matrices as second arguments, for example? If so, any opinions on implementation? a matlab user trying to get started with Numeric, Mark -------------- next part -------------- from Numeric import * # Notes: # I've used the existing MLab.py documentation conventions, not the pydoc # (PEP 256) ones. # # Optional arguments: Most of matlab's functions return 1 or more optional # arguments. I'm not sure what to do here, we could add a keyword argument # to each python function that is a flag specifying # whether or not to return the optional arguments. # Right now we return only the first result # def __tovector(M): """Convert an input array to a vector""" return (resize(M, (multiply.reduce(shape(M)),))) def find(M): """find(M) returns the indices where non-zero values occur in the input matrix. If M is a matrix, it is reshaped to a vector. Note that the indices returned are python-style (0...length-1) rather than Matlab-style (1...length).""" V = __tovector(M) return compress(M, arange(0,len(V))) ## Set functions # Notes: # unique is implemented by sorting the vectors first. The algorithm # is N*log(N) in speed (due to the sorting) and linear in N in # memory usage. Anyone have better ideas? You can use # equal.outer(N,N) but that's N^2 in both memory usage and speed. # ismember uses equal.outer and is thus linear in the sizes of both # vectors in terms of both speed and memory. If the vectors are of # equal size, that means the algorithm is N^2 in the size of the # vectors. This may be acceptable because the second vector is # generally much smaller than the first. There are probably better # ways to do it but my brain is tired. # # Index matrices as second arguments: see notes about optional arguments # above. def unique(N): """unique(N) returns a vector containing the same values as in N but with all repetitions removed. The result is sorted.""" # Matlab's unique accepts an N-d matrix but reshapes it to be a vector. # Also, Matlab's function always sorts. Nsort = sort(__tovector(N)) return concatenate(([Nsort[0]], compress(not_equal(Nsort[:-1], Nsort[1:]), Nsort[1:]))) def ismember(V,S): """ismember(V,S) returns a vector the same size as V containing 1 where the corresponding element of V is in the set S, and 0 otherwise.""" assert(len(shape(V)) == 1, 'First argument must be a vector') return logical_or.reduce(equal.outer(V,S),1) def intersect(M,N): """intersect(M,N) returns a vector whose elements are the elements that occur in both M and N. The result is sorted.""" uM = unique(M) return compress(ismember(uM, unique(N)), uM) def union(M,N): """union(M,N) returns a vector whose elements are the elements that occur in either M or N. The result is sorted.""" return unique(concatenate((M,N))) def setdiff(M,N): """setdiff(M,N) returns a vector containing all the elements of M that are not in N. The result is sorted.""" uM = unique(M) return compress(logical_not(ismember(uM, unique(N))), uM) def setxor(M,N): """setxor(M,N) returns a vector containing all the elements in the union of M and N that are not in the intersection of M and N. The result is sorted.""" return setdiff(union(M,N), intersect(M,N)) From Cath.Lawrence at anu.edu.au Wed Aug 7 20:18:01 2002 From: Cath.Lawrence at anu.edu.au (Cath Lawrence) Date: Wed Aug 7 20:18:01 2002 Subject: [Numpy-discussion] Newbie MA question Message-ID: <439BDEC6-AA7D-11D6-B128-00039390F614@anu.edu.au> Hi, I'm not sure this is the right list - looking at the archives you guys look more like developers more than users. Any pointers to the proper place, or TFMs to R, are welcome. (Yes, I have & have read the Numerical Python documentation.) That said, I'm trying to use masked arrays (for a bioinformatics app calculating stats on distances between pairs of amino acids, if you want to know) and am having a little trouble printing. One possible bug - "x.__str__()" and "x.__repr__()" show different typecodes. Example: >>> import MA >>> id = MA.identity(20) >>> r = MA.ones((20,20))*1.0 >>> rm = MA.MaskedArray(r, mask=id) >>> rm # ie, call x.__repr__() array(data = array (20,20) , type = d, has 400 elements, mask = array (20,20) , type = 1, has 400 elements, fill_value=[ 1.00000002e+20,]) >>> print rm # ie, call x.__str__() array (20,20) , type = O, has 400 elements >>> Secondly, I can't see how to make this print the whole thing if I want it. Which I do; all my matrices are 20*20 'cause there are 20 amino acids. The Numeric.array2string method can't be used because the data is always masked. The best I've found so far is to make a Numeric array by filling with an impossible number like -1, then use array2string. But visually it would be nicer to see the masked values as "--". Thanks for any help, regards, Cath Cath Lawrence, Cath.Lawrence at anu.edu.au Scientific Programmer, Centre for Bioinformation Science, John Curtin School of Medical Research Australian National University, Canberra ACT 0200 ph: Maths (02) 6125 2904; JCSMR (02) 6125 0417; mobile: 0421-902694 fax: (02) 61254712 From reggie at merfinllc.com Thu Aug 8 10:10:03 2002 From: reggie at merfinllc.com (Reggie Dugard) Date: Thu Aug 8 10:10:03 2002 Subject: [Numpy-discussion] Newbie MA question In-Reply-To: <439BDEC6-AA7D-11D6-B128-00039390F614@anu.edu.au> References: <439BDEC6-AA7D-11D6-B128-00039390F614@anu.edu.au> Message-ID: <1028826573.3624.8.camel@auk> Cath, The simple answer to your question is to use MA.set_print_limit(0) to change the behavior of str and repr back to the standard Numeric behavior of always printing the entire array. Then you will get the whole array, with the masked values as '--'. Reggie > Hi, > > I'm not sure this is the right list - looking at the archives you guys > look more like developers more than users. > > Any pointers to the proper place, or TFMs to R, are welcome. (Yes, I > have & have read the Numerical Python documentation.) > > That said, I'm trying to use masked arrays (for a bioinformatics app > calculating stats on distances between pairs of amino acids, if you want > to know) and am having a little trouble printing. > > One possible bug - "x.__str__()" and "x.__repr__()" show different > typecodes. > Example: > >>> import MA > >>> id = MA.identity(20) > >>> r = MA.ones((20,20))*1.0 > >>> rm = MA.MaskedArray(r, mask=id) > >>> rm # ie, call x.__repr__() > array(data = > array (20,20) , type = d, has 400 elements, > mask = > array (20,20) , type = 1, has 400 elements, > fill_value=[ 1.00000002e+20,]) > > >>> print rm # ie, call x.__str__() > array (20,20) , type = O, has 400 elements > >>> > > Secondly, I can't see how to make this print the whole thing if I want > it. Which I do; all my matrices are 20*20 'cause there are 20 amino > acids. > > The Numeric.array2string method can't be used because the data is always > masked. > The best I've found so far is to make a Numeric array by filling with an > impossible number like -1, then use array2string. But visually it would > be nicer to see the masked values as "--". > > Thanks for any help, > regards, > Cath > Cath Lawrence, Cath.Lawrence at anu.edu.au > Scientific Programmer, Centre for Bioinformation Science, > John Curtin School of Medical Research > Australian National University, Canberra ACT 0200 > ph: Maths (02) 6125 2904; JCSMR (02) 6125 0417; > mobile: 0421-902694 fax: (02) 61254712 > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Numpy-discussion mailing list > Numpy-discussion at lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/numpy-discussion From bryan.cole at teraview.co.uk Fri Aug 9 08:52:19 2002 From: bryan.cole at teraview.co.uk (bryan cole) Date: Fri Aug 9 08:52:19 2002 Subject: [Numpy-discussion] floating point exceptions Message-ID: <1028908341.14048.51.camel@bryan.teraviewhq.local> I've just ported a Numeric+Python program from windows to linux and I'm generating floating point exceptions in the linux version which did not occur in windows. I'm trying to generate a gaussian distribution by: Input = Numeric.arange(-1024,1024)/20.0 Output = Numeric.exp(-(Input**2)) At the edges of the distribution the largish negative arguments cause the f.p. exception and prevent calculation of the entire array. On windows the underflow errors are presumably rounded down to 0.0 automatically. Is it possible to get this behaviour on linux/ix86? Anyone got any suggestions on a workarround for this? I see the numpy docs suggest using Masked Arrays, but since I don't know in advance which array items will generate the exceptions, I don't know which items to mask. Can the MA module generate an array mask based on f.p. exceptions from a calculation? any suggestions would be much appreciated. Bryan -- Bryan Cole Teraview Ltd., 302-304 Cambridge Science Park, Milton Road, Cambridge CB4 0WG, United Kingdom. tel: +44 (1223) 435380 / 435386 (direct-dial) fax: +44 (1223) 435382 From bryan.cole at teraview.co.uk Fri Aug 9 09:21:04 2002 From: bryan.cole at teraview.co.uk (bryan cole) Date: Fri Aug 9 09:21:04 2002 Subject: [Numpy-discussion] floating point exceptions In-Reply-To: <1028908341.14048.51.camel@bryan.teraviewhq.local> References: <1028908341.14048.51.camel@bryan.teraviewhq.local> Message-ID: <1028910157.15155.57.camel@bryan.teraviewhq.local> OK, I've worked out how to do this with MA. I mask the Numeric array input to MA.exp() using MA.masked_outside( ... ,-700, 700) then convert the result back to a Numeric array using MA.filled( ..., 0.0) then continue as normal. I'm still interested if there's a more elegant approach. Bryan On Fri, 2002-08-09 at 16:52, bryan cole wrote: > I've just ported a Numeric+Python program from windows to linux and I'm > generating floating point exceptions in the linux version which did not > occur in windows. > > I'm trying to generate a gaussian distribution by: > > Input = Numeric.arange(-1024,1024)/20.0 > Output = Numeric.exp(-(Input**2)) > > At the edges of the distribution the largish negative arguments cause > the f.p. exception and prevent calculation of the entire array. > > On windows the underflow errors are presumably rounded down to 0.0 > automatically. Is it possible to get this behaviour on linux/ix86? > > Anyone got any suggestions on a workarround for this? I see the numpy > docs suggest using Masked Arrays, but since I don't know in advance > which array items will generate the exceptions, I don't know which items > to mask. Can the MA module generate an array mask based on f.p. > exceptions from a calculation? > > any suggestions would be much appreciated. > > Bryan > > > -- > Bryan Cole > Teraview Ltd., 302-304 Cambridge Science Park, Milton Road, Cambridge > CB4 0WG, United Kingdom. > tel: +44 (1223) 435380 / 435386 (direct-dial) fax: +44 (1223) 435382 > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Numpy-discussion mailing list > Numpy-discussion at lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/numpy-discussion -- Bryan Cole Teraview Ltd., 302-304 Cambridge Science Park, Milton Road, Cambridge CB4 0WG, United Kingdom. tel: +44 (1223) 435380 / 435386 (direct-dial) fax: +44 (1223) 435382 From james.analytis at physics.ox.ac.uk Sun Aug 11 16:01:02 2002 From: james.analytis at physics.ox.ac.uk (James G Analytis) Date: Sun Aug 11 16:01:02 2002 Subject: [Numpy-discussion] QR algorithms in Python Message-ID: <200208120000.00948.james.analytis@physics.ox.ac.uk> Hi, I'm looking for a QR algorithm that can decompose complex matrices. The LinearAlgebra package from Numeric doesn't seem to have it. SciPy's linalg package is still on the way, so I can't use that either. Matfunc's QR decomposition only works for real matrices. This problem came up two years ago on this same discussion panel, and Konrad Hinsen recommended that the user download PyLapack from ftp://dirac.cnrs-orleans.fr/pub/ I cannot compile PyLapack because I get this problem: [analytis at toomey Modules]$ python2 compile.py Copy Misc/Makefile.pre.in from the Python distribution to this directory and try again. make: Makefile.pre.in: No such file or directory make: *** No rule to make target `Makefile.pre.in'. Stop. make: *** No targets specified and no makefile found. Stop. [analytis at toomey Modules]$ I think the Makefile searched for is one from an earlier version of Numeric (the tar file is 2yrs old). Any suggestions? Cheers, James From nwagner at mecha.uni-stuttgart.de Mon Aug 12 00:59:02 2002 From: nwagner at mecha.uni-stuttgart.de (Nils Wagner) Date: Mon Aug 12 00:59:02 2002 Subject: [Numpy-discussion] Scientific data - Reading files Message-ID: <3D576C60.13F75D35@mecha.uni-stuttgart.de> Hi, I have collected acceleration data by a multi-channel data acquisition system. Each file (E1431A*.DAT) contains one column with real numbers. The contents of the i-th file should be stored in the i-th row of a data matrix A. How can I manage this task efficiently ? Are there suitable python modules for this purpose ? A small example would be appreciated. Nils From pearu at cens.ioc.ee Mon Aug 12 01:06:04 2002 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Mon Aug 12 01:06:04 2002 Subject: [Numpy-discussion] QR algorithms in Python In-Reply-To: <200208120000.00948.james.analytis@physics.ox.ac.uk> Message-ID: On Mon, 12 Aug 2002, James G Analytis wrote: > Hi, > I'm looking for a QR algorithm that can decompose complex matrices. The > LinearAlgebra package from Numeric doesn't seem to have it. SciPy's linalg > package is still on the way, so I can't use that either. Try SciPy's linalg package again (from CVS), the QR functions is working now: >>> from scipy import linalg >>> from Numeric import dot >>> q,r=linalg.qr([[1,2],[3j,4]]) >>> print q [[-0.31622777+0.j -0.78935222-0.52623481j] [ 0. -0.9486833j -0.1754116 +0.26311741j]] >>> print r [[-3.16227766+0.j -0.63245553+3.79473319j] [ 0. +0.j -2.28035085+0.j ]] >>> print dot(q,r) [[ 1. +0.00000000e+00j 2. -8.71264866e-16j] [ 0. +3.00000000e+00j 4. +3.09051829e-16j]] Regards, Pearu From hinsen at cnrs-orleans.fr Mon Aug 12 06:01:03 2002 From: hinsen at cnrs-orleans.fr (Konrad Hinsen) Date: Mon Aug 12 06:01:03 2002 Subject: [Numpy-discussion] floating point exceptions In-Reply-To: <1028908341.14048.51.camel@bryan.teraviewhq.local> References: <1028908341.14048.51.camel@bryan.teraviewhq.local> Message-ID: bryan cole writes: > I'm trying to generate a gaussian distribution by: > > Input = Numeric.arange(-1024,1024)/20.0 > Output = Numeric.exp(-(Input**2)) > > At the edges of the distribution the largish negative arguments cause > the f.p. exception and prevent calculation of the entire array. > > On windows the underflow errors are presumably rounded down to 0.0 > automatically. Is it possible to get this behaviour on linux/ix86? Yes, rebuild the Python interpreter (not NumPy!) and add the compilation option "-lieee". Alternatively, download and install the current development version of Python from the CVS server (I haven't tried it, but it is supposed to fix this problem as well). Ultimately the problem is in the C standard library. On some platforms it signals underflow as an overflow error, on others it doesn't. Python thus has to get work around such problems in a platform-specific way. Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen at cnrs-orleans.fr Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24 Rue Charles Sadron | Fax: +33-2.38.63.15.17 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ France | Nederlands/Francais ------------------------------------------------------------------------------- From hinsen at cnrs-orleans.fr Mon Aug 12 06:04:01 2002 From: hinsen at cnrs-orleans.fr (Konrad Hinsen) Date: Mon Aug 12 06:04:01 2002 Subject: [Numpy-discussion] QR algorithms in Python In-Reply-To: <200208120000.00948.james.analytis@physics.ox.ac.uk> References: <200208120000.00948.james.analytis@physics.ox.ac.uk> Message-ID: James G Analytis writes: > I cannot compile PyLapack because I get this problem: > > [analytis at toomey Modules]$ python2 compile.py > Copy Misc/Makefile.pre.in from the Python distribution > to this directory and try again. > make: Makefile.pre.in: No such file or directory The old module compilation procedure via Makefile.pre.in does not exist any more in Python 2.2. If and when I find the time, I'll write a distutils script for PyLapack. Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen at cnrs-orleans.fr Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24 Rue Charles Sadron | Fax: +33-2.38.63.15.17 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ France | Nederlands/Francais ------------------------------------------------------------------------------- From Chris.Barker at noaa.gov Mon Aug 12 12:16:08 2002 From: Chris.Barker at noaa.gov (Chris Barker) Date: Mon Aug 12 12:16:08 2002 Subject: [Numpy-discussion] Scientific data - Reading files References: <3D576C60.13F75D35@mecha.uni-stuttgart.de> Message-ID: <3D57F995.958A9E75@noaa.gov> Nils Wagner wrote: > Each file (E1431A*.DAT) contains > one column with real numbers. The contents of the i-th file should be > stored in the i-th row of a data matrix A. Are the files binary or ASCI ? if ASCI, look in Scipy, there are a couple of modules for this kind of thing, I doubt any of them are set up for multiple files, so you'll have to loop through the file list. If binary, you can do something like: while row < NumRows: file = open(filename,'rb') A[row,:] = fromstring(file.read(),Float) # make sure you get the typecode right! file.close() row += 1 WARNING: not the least bit tested. -Chris -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov From james.analytis at physics.ox.ac.uk Tue Aug 13 04:36:03 2002 From: james.analytis at physics.ox.ac.uk (James G Analytis) Date: Tue Aug 13 04:36:03 2002 Subject: [Numpy-discussion] QR algorithms in Python In-Reply-To: References: Message-ID: <200208131235.05006.james.analytis@physics.ox.ac.uk> Dear Pearu, SciPy's linalg modules are just what I need. However, I get the following problem on importing SciPy: [analytis at toomey analytis]$ python2 Python 2.2 (#1, Apr 12 2002, 15:29:57) [GCC 2.96 20000731 (Red Hat Linux 7.2 2.96-109)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import scipy exceptions.ImportError: /usr/lib/python2.2/site-packages/scipy/linalg/flapack.so : undefined symbol: sgesdd_ exceptions.ImportError: /usr/lib/python2.2/site-packages/scipy/linalg/_flinalg.s o: undefined symbol: dlaswp_ Traceback (most recent call last): File "", line 1, in ? File "/tmp/SciPyTest/linux2/lib/python2.2/site-packages/scipy/__init__.py", li ne 42, in ? File "/usr/lib/python2.2/site-packages/scipy/special/__init__.py", line 328, i n ? import orthogonal File "/usr/lib/python2.2/site-packages/scipy/special/orthogonal.py", line 59, in ? from scipy.linalg import eig File "/tmp/SciPyTest/linux2/lib/python2.2/site-packages/scipy/linalg/__init__. py", line 40, in ? File "/tmp/SciPyTest/linux2/lib/python2.2/site-packages/scipy/linalg/basic.py" , line 17, in ? ImportError: /usr/lib/python2.2/site-packages/scipy/linalg/calc_lwork.so: undefi ned symbol: ieeeck_ >>> I am running standard Red Hat 7.3 with a smp kernel, on a dual-processor PIII. Is there anything I should watch out for (compiler issues perhaps)? I appreciate the help! Cheers, James On Monday 12 Aug 2002 9:04 am, Pearu Peterson wrote: > On Mon, 12 Aug 2002, James G Analytis wrote: > > Hi, > > I'm looking for a QR algorithm that can decompose complex matrices. The > > LinearAlgebra package from Numeric doesn't seem to have it. SciPy's > > linalg package is still on the way, so I can't use that either. > > Try SciPy's linalg package again (from CVS), the QR functions is working > > now: > >>> from scipy import linalg > >>> from Numeric import dot > >>> q,r=linalg.qr([[1,2],[3j,4]]) > >>> print q > > [[-0.31622777+0.j -0.78935222-0.52623481j] > [ 0. -0.9486833j -0.1754116 +0.26311741j]] > > >>> print r > > [[-3.16227766+0.j -0.63245553+3.79473319j] > [ 0. +0.j -2.28035085+0.j ]] > > >>> print dot(q,r) > > [[ 1. +0.00000000e+00j 2. -8.71264866e-16j] > [ 0. +3.00000000e+00j 4. +3.09051829e-16j]] > > Regards, > Pearu From nwagner at mecha.uni-stuttgart.de Tue Aug 13 04:53:02 2002 From: nwagner at mecha.uni-stuttgart.de (Nils Wagner) Date: Tue Aug 13 04:53:02 2002 Subject: [Numpy-discussion] QR algorithms in Python References: <200208131235.05006.james.analytis@physics.ox.ac.uk> Message-ID: <3D58F4A9.BFE43265@mecha.uni-stuttgart.de> James G Analytis schrieb: > > Dear Pearu, > SciPy's linalg modules are just what I need. However, I get the following > problem on importing SciPy: > ATLAS is also required. http://math-atlas.sourceforge.net/ Nils > [analytis at toomey analytis]$ python2 > Python 2.2 (#1, Apr 12 2002, 15:29:57) > [GCC 2.96 20000731 (Red Hat Linux 7.2 2.96-109)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import scipy > exceptions.ImportError: > /usr/lib/python2.2/site-packages/scipy/linalg/flapack.so : undefined > symbol: sgesdd_ > exceptions.ImportError: > /usr/lib/python2.2/site-packages/scipy/linalg/_flinalg.s o: undefined > symbol: dlaswp_ > Traceback (most recent call last): > File "", line 1, in ? > File "/tmp/SciPyTest/linux2/lib/python2.2/site-packages/scipy/__init__.py", > li ne 42, in ? > File "/usr/lib/python2.2/site-packages/scipy/special/__init__.py", line 328, > i n ? > import orthogonal > File "/usr/lib/python2.2/site-packages/scipy/special/orthogonal.py", line > 59, in ? > from scipy.linalg import eig > File > "/tmp/SciPyTest/linux2/lib/python2.2/site-packages/scipy/linalg/__init__. > py", line 40, in ? > File > "/tmp/SciPyTest/linux2/lib/python2.2/site-packages/scipy/linalg/basic.py" > , line 17, in ? > ImportError: /usr/lib/python2.2/site-packages/scipy/linalg/calc_lwork.so: > undefi ned symbol: ieeeck_ > >>> > > I am running standard Red Hat 7.3 with a smp kernel, on a dual-processor PIII. > Is there anything I should watch out for (compiler issues perhaps)? > I appreciate the help! > Cheers, > James > > On Monday 12 Aug 2002 9:04 am, Pearu Peterson wrote: > > On Mon, 12 Aug 2002, James G Analytis wrote: > > > Hi, > > > I'm looking for a QR algorithm that can decompose complex matrices. The > > > LinearAlgebra package from Numeric doesn't seem to have it. SciPy's > > > linalg package is still on the way, so I can't use that either. > > > > Try SciPy's linalg package again (from CVS), the QR functions is working > > > > now: > > >>> from scipy import linalg > > >>> from Numeric import dot > > >>> q,r=linalg.qr([[1,2],[3j,4]]) > > >>> print q > > > > [[-0.31622777+0.j -0.78935222-0.52623481j] > > [ 0. -0.9486833j -0.1754116 +0.26311741j]] > > > > >>> print r > > > > [[-3.16227766+0.j -0.63245553+3.79473319j] > > [ 0. +0.j -2.28035085+0.j ]] > > > > >>> print dot(q,r) > > > > [[ 1. +0.00000000e+00j 2. -8.71264866e-16j] > > [ 0. +3.00000000e+00j 4. +3.09051829e-16j]] > > > > Regards, > > Pearu > > ------------------------------------------------------- > This sf.net email is sponsored by: Dice - The leading online job board > for high-tech professionals. Search and apply for tech jobs today! > http://seeker.dice.com/seeker.epl?rel_code1 > _______________________________________________ > Numpy-discussion mailing list > Numpy-discussion at lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/numpy-discussion From paul at pfdubois.com Thu Aug 15 11:41:01 2002 From: paul at pfdubois.com (Paul F Dubois) Date: Thu Aug 15 11:41:01 2002 Subject: [Numpy-discussion] [ANNOUNCE] Pyfort 8.2 and video tutorials for Python, Pyfort Message-ID: <000001c2448b$19b1f0b0$0a01a8c0@NICKLEBY> Pyfortran 8.2 is available. The setup bug for Windows is fixed and a -n option has been added to just generate glue code and stop. Video tutorials are now available at http://esg.llnl.gov/cdat/ (go to documentation and tutorials). There are instructions online about how to set up your computer to play these videos. The Linux instructions may or may not work for you; for the moment we recommend viewing from Windows. These tutorials are mostly for CDAT users, but there are two for Pyfort and one short "Introduction to Python". Our most excellent summer student from USC, Tasha Drew, got everything working. From jochen at jochen-kuepper.de Sun Aug 18 14:30:02 2002 From: jochen at jochen-kuepper.de (Jochen =?iso-8859-1?q?K=FCpper?=) Date: Sun Aug 18 14:30:02 2002 Subject: [Numpy-discussion] Re: numarray: RandomArray2 In-Reply-To: <3D5F8F5E.9070700@stsci.edu> References: <3D5F8F5E.9070700@stsci.edu> Message-ID: On Sun, 18 Aug 2002 08:13:18 -0400 Todd Miller wrote: Todd> Jochen K?pper wrote: >> Looking at RandomArray2 I realized that the functions don't do any >> argument checking. Shouldn't uniform for example check at least >> whether ,---- >> | minimum != maximum >> `---- >> or even make sure that maximum > minimum? (Although the result is >> probably "ok" if it isn't.) Something like >> ,---- >> | def uniform(minimum, maximum, shape=[]): >> | """Return array of random Floats in interval ]minimum, maximum[ >> | with shape |shape|. >> | """ >> | if maximum <= minimum: >> | raise ValueError >> | return minimum + (maximum-minimum)*random(shape) >> `---- >> Todd> I am +0 on this. The parameter order emulates "range". Not exactly, currently: ,---- | >>> range(2, -4) | [] | >>> ran.uniform(2, -4) | -2.2346744537353516 `---- That is, if max < min range returns an empty list, whereas uniform comes up with the same result as for (-4, 2) (well, "mirrored"). Also note the "strange" docstring of range: ,---- | range(...) | range([start,] stop[, step]) -> list of integers `---- pointing straight toward its behavior. Todd> While it does look like it will compute the wrong answer if Todd> called incorrectly, that seems unlikely to me. Well, if max>> import RandomArray2 as ran | >>> ran.uniform(1, 1) | 1.0 `---- So well, maybe someone with insight into RNG's can comment on the, mirroring issue? >> Moreover there are some inconsistencies between functions, i.e.: >> ,---- >> | def randint(minimum, maximum=None, shape=[]): >> `---- >> ,---- >> | def random_integers(maximum, minimum=1, shape=[]): >> `---- Todd> It appears to me that the parameter order of randint again Todd> emulates "range". The fact that random_integers is not Todd> consistent with randint seem OK to me because random_integers Todd> appears to have been written expressly to tailor the calling Todd> sequence of randint. Hmm, v.s. Yes, initially I wondered why there are two functions at all. This explanation sounds like "we wanted some help in confusing the users" :)) Todd> Because randint re-defines its parameters depending on whether 1 Todd> or 2 range values are used, as does range, I don't think there Todd> is a completely consistent way to do this. Either we're "wrong" Todd> for the 1 parameter case or the 2 parameter case. The way it is Todd> specified now seems simplest to me, with "minimum" preceding Todd> "maximum", even though it is not strictly the correct name for Todd> the 1 parameter case. What's about ,---- | uniform(limit1, limit2, shape=[]) `---- and then range-like behaviour? But then, what do we return on ,---- | uniform(2, -4) `---- ??? To make it compatible with range, it should be an empty list, no? Your-even-more-confused-ly's, Jochen -- Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de Libert?, ?galit?, Fraternit? GnuPG key: 44BCCD8E Sex, drugs and rock-n-roll From frank.horowitz at csiro.au Sun Aug 18 23:50:01 2002 From: frank.horowitz at csiro.au (Frank Horowitz) Date: Sun Aug 18 23:50:01 2002 Subject: [Numpy-discussion] Pyrex now interfaces with NumPy (old) array internals In-Reply-To: References: Message-ID: <1029739738.8282.7.camel@bonzo> Perhaps this is best left to Greg Ward, but I just thought that I'd point out to the list that Pyrex in the latest version 0.4.1 successfully interfaces with the (original) Numeric array data types. There are examples in both the Demo subdirectory and in the website's FAQ. Another alternative for getting performance, interfacing to C libraries, and even calling Fortran (from Pyrex's Python/C hybrid code). Frank (Choice is Good ;-) Horowitz From jmiller at stsci.edu Mon Aug 19 06:28:09 2002 From: jmiller at stsci.edu (Todd Miller) Date: Mon Aug 19 06:28:09 2002 Subject: [Numpy-discussion] Re: numarray: RandomArray2 References: <3D5F8F5E.9070700@stsci.edu> Message-ID: <3D60F247.60603@stsci.edu> Jochen K?pper wrote: >On Sun, 18 Aug 2002 08:13:18 -0400 Todd Miller wrote: > >Todd> Jochen K?pper wrote: > >>>Looking at RandomArray2 I realized that the functions don't do any >>>argument checking. Shouldn't uniform for example check at least >>>whether ,---- >>>| minimum != maximum >>>`---- >>>or even make sure that maximum > minimum? (Although the result is >>>probably "ok" if it isn't.) Something like >>>,---- >>>| def uniform(minimum, maximum, shape=[]): >>>| """Return array of random Floats in interval ]minimum, maximum[ >>>| with shape |shape|. >>>| """ >>>| if maximum <= minimum: >>>| raise ValueError >>>| return minimum + (maximum-minimum)*random(shape) >>>`---- >>> >Todd> I am +0 on this. The parameter order emulates "range". > >Not exactly, currently: >,---- >| >>> range(2, -4) >| [] >| >>> ran.uniform(2, -4) >| -2.2346744537353516 >`---- >That is, if max < min range returns an empty list, whereas uniform >comes up with the same result as for (-4, 2) (well, "mirrored"). > >Also note the "strange" docstring of range: >,---- >| range(...) >| range([start,] stop[, step]) -> list of integers >`---- >pointing straight toward its behavior. > >Todd> While it does look like it will compute the wrong answer if >Todd> called incorrectly, that seems unlikely to me. > >Well, if maxproblem as long as it is done "consistently". I don't have enough >knowledge of RNG's to understand whether it is a problem (with respect >to randomness) when calls with the right and wrong ordering of min and >max are mixed. > >Thinking about the case min==max I must say it's a very wasted >function call, but no actually big deal: >,---- >| >>> import RandomArray2 as ran >| >>> ran.uniform(1, 1) >| 1.0 >`---- > >So well, maybe someone with insight into RNG's can comment on the, >mirroring issue? > >>>Moreover there are some inconsistencies between functions, i.e.: >>>,---- >>>| def randint(minimum, maximum=None, shape=[]): >>>`---- >>>,---- >>>| def random_integers(maximum, minimum=1, shape=[]): >>>`---- >>> > >Todd> It appears to me that the parameter order of randint again >Todd> emulates "range". The fact that random_integers is not >Todd> consistent with randint seem OK to me because random_integers >Todd> appears to have been written expressly to tailor the calling >Todd> sequence of randint. > >Hmm, > >v.s. > >Yes, initially I wondered why there are two functions at all. This >explanation sounds like "we wanted some help in confusing the >users" :)) > I read it more like: someone wanted to make one particular user happy by giving them the interface they asked for. Since writing random_integers was easy, they did it even though it amounted to a small duplication of effort and interface functionality. But, I'm just speculating. > >Todd> Because randint re-defines its parameters depending on whether 1 >Todd> or 2 range values are used, as does range, I don't think there >Todd> is a completely consistent way to do this. Either we're "wrong" >Todd> for the 1 parameter case or the 2 parameter case. The way it is >Todd> specified now seems simplest to me, with "minimum" preceding >Todd> "maximum", even though it is not strictly the correct name for >Todd> the 1 parameter case. > >What's about >,---- >| uniform(limit1, limit2, shape=[]) >`---- >and then range-like behaviour? > >But then, what do we return on >,---- >| uniform(2, -4) >`---- >??? > Perhaps my intuition about "range" was incorrect, or we're taking the analogy too far. It seems to me that randint is returning random numbers between two limits, and the order of the limits is irrelevant. randint(2,-4) is identical to randint(-4,2). As you have pointed out, this is distinctly different than range. At this point, I'm still unconvinced that the world would be made a better place either by raising an exception or by changing the semantics to return an "empty array". That small change seems just as likely to upset some user as to make another happy. >Your-even-more-confused-ly's, >Jochen > Todd -- Todd Miller jmiller at stsci.edu STSCI / SSG From jochen at unc.edu Mon Aug 19 09:34:02 2002 From: jochen at unc.edu (Jochen =?iso-8859-1?q?K=FCpper?=) Date: Mon Aug 19 09:34:02 2002 Subject: [Numpy-discussion] Re: numarray In-Reply-To: <3D5F9140.6060304@stsci.edu> References: <3D5F9140.6060304@stsci.edu> Message-ID: On Sun, 18 Aug 2002 08:21:20 -0400 Todd Miller wrote: >> The following patch is required for Cygwin: >> >> Index: Src/_chararraymodule.c >> Todd> I'll apply this. Applied. >> ,---- >> | ***************************************************************** >> | Failure in example: >> | array([1, 8, 100, 100], type=Int8) * array([1, 8, 100, -100], type=Int8) >> | from line #1671 of numtest >> | Expected: >> | Warning: Encountered overflow(s) in multiply >> | array([ 1, 64, 127, -128], type=Int8) >> | Got: array([ 1, 64, 127, -128], type=Int8) >> | ***************************************************************** >> `---- Todd> This overflow exception issue came up earlier this year with Todd> IRIX. My guess is that the function int_overflow_error() in Todd> codegenerator.py is not working correctly. The suggested Todd> temporary patch at the time was: [patch against codegenerator.py] Todd> If you try it out and it solves the problem for Cygwin, we Todd> should probably change it universally. No, it doesn't solve the problem. I hope to find some time later this week to look at it. Greetings, Jochen -- University of North Carolina phone: +1-919-962-4403 Department of Chemistry phone: +1-919-962-1579 Venable Hall CB#3290 (Kenan C148) fax: +1-919-843-6041 Chapel Hill, NC 27599, USA GnuPG key: 44BCCD8E From jochen at unc.edu Mon Aug 19 15:54:02 2002 From: jochen at unc.edu (Jochen =?iso-8859-1?q?K=FCpper?=) Date: Mon Aug 19 15:54:02 2002 Subject: [Numpy-discussion] numarray on Cygwin Message-ID: Hi, I could succesfully compile numarray (see numpy.org) on Cygwin (updated last week), using the standard Cygwin python. However many tests fail, due to "missing" overflow or "division by zero" exceptions. I took a quick look at the test-failures of numarray on numpy. The first problem is that we don't get a "Overflow error" warning when it is expected: ,----[Cygwin] | >>> array([1, 8, 100, 100], type=Int8) * array([1, 8, 100, -100], type=Int8) | array([ 1, 64, 127, -128], type=Int8) `---- Whereas on Linux we get ,----[Linux] | >>> array([1, 8, 100, 100], type=Int8) * array([1, 8, 100, -100], type=Int8) | Warning: Encountered overflow(s) in multiply | array([ 1, 64, 127, -128], type=Int8) `---- Is this related to a configuration option of python (--with-sigfpe ?) or a "feature" of the Cygwin libm/libc? Any ideas? Btw, I tried to rebuild python (cvs maint22-release patched for _socket) but got the following errors with the math module (similar for cmath): ,---- | gcc -shared -Wl,--enable-auto-image-base build/temp.cygwin-1.3.12-i686-2.2/mathmodule.o -L/usr/local/lib -L. -lm -lpython2.2 -o build/lib.cygwin-1.3.12-i686-2.2/math.dll | build/temp.cygwin-1.3.12-i686-2.2/mathmodule.o: In function `math_1': | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:57: undefined reference to `PyFPE_counter' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:57: undefined reference to `PyFPE_counter' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:57: undefined reference to `PyFPE_jbuf' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:57: undefined reference to `PyFPE_counter' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:59: undefined reference to `PyFPE_dummy' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:59: undefined reference to `PyFPE_counter' | build/temp.cygwin-1.3.12-i686-2.2/mathmodule.o: In function `math_2': | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:74: undefined reference to `PyFPE_counter' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:74: undefined reference to `PyFPE_counter' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:74: undefined reference to `PyFPE_jbuf' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:74: undefined reference to `PyFPE_counter' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:76: undefined reference to `PyFPE_dummy' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:76: undefined reference to `PyFPE_counter' | build/temp.cygwin-1.3.12-i686-2.2/mathmodule.o: In function `math_ldexp': | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:173: undefined reference to `PyFPE_counter' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:173: undefined reference to `PyFPE_counter' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:173: undefined reference to `PyFPE_jbuf' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:173: undefined reference to `PyFPE_counter' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:175: undefined reference to `PyFPE_dummy' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:175: undefined reference to `PyFPE_counter' | collect2: ld returned 1 exit status | WARNING: building of extension "math" failed: command 'gcc' failed with exit status 1 `---- Greetings, Jochen -- University of North Carolina phone: +1-919-962-4403 Department of Chemistry phone: +1-919-962-1579 Venable Hall CB#3290 (Kenan C148) fax: +1-919-843-6041 Chapel Hill, NC 27599, USA GnuPG key: 44BCCD8E From jochen at unc.edu Tue Aug 20 08:52:04 2002 From: jochen at unc.edu (Jochen =?iso-8859-1?q?K=FCpper?=) Date: Tue Aug 20 08:52:04 2002 Subject: [Numpy-discussion] Cygwin floating point control Message-ID: The following program does not link on Cygwin ,---- | #include | | int main() | { | return(fgetsticky()); | } `---- due to fpgetsticky beeing unresolved. fpgetsticky is declared in /usr/include/ieeefp.h, but I cannot find any library it is defined in. A search on the Cywin site and at google didn't turn up anything for fpgetsticky on Cygwin. (?) Is it implemented? If so, where? If not, is there any substitute I should be using? Greetings, Jochen PS: It would be nice if you could cc me. -- University of North Carolina phone: +1-919-962-4403 Department of Chemistry phone: +1-919-962-1579 Venable Hall CB#3290 (Kenan C148) fax: +1-919-843-6041 Chapel Hill, NC 27599, USA GnuPG key: 44BCCD8E From nhv at cape.com Tue Aug 20 11:47:05 2002 From: nhv at cape.com (Norman Vine) Date: Tue Aug 20 11:47:05 2002 Subject: [Numpy-discussion] RE: Cygwin floating point control In-Reply-To: Message-ID: <037601c2487a$88f717a0$a300a8c0@nhv> Jochen K?pper writes: > >The following program does not link on Cygwin >,---- >| #include >| >| int main() >| { >| return(fgetsticky()); >| } >`---- >due to fpgetsticky beeing unresolved. > >fpgetsticky is declared in /usr/include/ieeefp.h, but I cannot find >any library it is defined in. A search on the Cywin site and at >google didn't turn up anything for fpgetsticky on Cygwin. (?) > >Is it implemented? If so, where? If not, is there any substitute I >should be using? I use this 'home spun' header that I 'hacked' from the BSD sources Not really sure if it is 100% right or if the license allows this to be used in Cygwin 'proper' but ... it seems to work for me HTH Norman -------------- next part -------------- A non-text attachment was scrubbed... Name: fpu.tgz Type: application/x-compressed Size: 2573 bytes Desc: not available URL: From jochen at jochen-kuepper.de Tue Aug 20 19:39:02 2002 From: jochen at jochen-kuepper.de (Jochen =?iso-8859-1?q?K=FCpper?=) Date: Tue Aug 20 19:39:02 2002 Subject: [Numpy-discussion] numarray -- correlate Message-ID: Is there any good reason to not rename Convolve.cross_correlate to correlate? That fits the other names much better. If needed (aka backwards-compatibility to numpy) we could even provide an alias cross_correlate -- probably documented to be deprecated... But since you have to load a separate module anyway, I think we can rename the function just as well. Greetings, Jochen -- Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de Libert?, ?galit?, Fraternit? GnuPG key: 44BCCD8E Sex, drugs and rock-n-roll From jmiller at stsci.edu Wed Aug 21 05:51:02 2002 From: jmiller at stsci.edu (Todd Miller) Date: Wed Aug 21 05:51:02 2002 Subject: [Numpy-discussion] Re: numarray -- correlate References: Message-ID: <3D638C6C.9090703@stsci.edu> Jochen K?pper wrote: >Is there any good reason to not rename Convolve.cross_correlate to >correlate? That fits the other names much better. > I agree. > >If needed (aka backwards-compatibility to numpy) we could even provide >an alias cross_correlate -- probably documented to be deprecated... But >since you have to load a separate module anyway, I think we can rename >the function just as well. > Please do this. > >Greetings, >Jochen > Todd -- Todd Miller jmiller at stsci.edu STSCI / SSG From jochen at jochen-kuepper.de Wed Aug 21 07:12:09 2002 From: jochen at jochen-kuepper.de (Jochen =?iso-8859-1?q?K=FCpper?=) Date: Wed Aug 21 07:12:09 2002 Subject: [Numpy-discussion] Re: numarray -- correlate In-Reply-To: <3D638C6C.9090703@stsci.edu> References: <3D638C6C.9090703@stsci.edu> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Wed, 21 Aug 2002 08:49:48 -0400 Todd Miller wrote: Todd> Jochen K?pper wrote: >> Is there any good reason to not rename Convolve.cross_correlate to >> correlate? That fits the other names much better. >> Todd> I agree. >> >> If needed (aka backwards-compatibility to numpy) we could even provide >> an alias cross_correlate -- probably documented to be deprecated... Do we need this? >> But since you have to load a separate module anyway, I think we can >> rename the function just as well. >> Todd> Please do this. Done. Greetings, Jochen - -- Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de Libert?, ?galit?, Fraternit? GnuPG key: 44BCCD8E Sex, drugs and rock-n-roll -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: Processed by Mailcrypt and GnuPG iD8DBQE9Y58ciJ/aUUS8zY4RAqeBAKCeAjeXmvl01zgU5trFmh6hteeF1wCgvYYY cbmMNmYlVQF5rqPBczBYsq4= =6eTq -----END PGP SIGNATURE----- From jochen at jochen-kuepper.de Wed Aug 21 20:56:02 2002 From: jochen at jochen-kuepper.de (Jochen =?iso-8859-1?q?K=FCpper?=) Date: Wed Aug 21 20:56:02 2002 Subject: [Numpy-discussion] numarray, Convolve, and lineshapes Message-ID: Looking at Convolve last night I came up with the idea that we often need to convolute datasets with common profiles, such as Gauss- or Voigt-lineshapes, for example. So tonight I took my old module I had for that purpose apart and put it as submodule into Convolve. Well, currently it really only supports Gauss, Lorentz, and Voigt, but the general "framework" to add more profiles is there. Adding a new one would consist of defining a new derived class (overall 5 lines of code) and providing a function that calculates the actual line profile. I chose the implementation using functor classes so profiles can be reused. I am aware that there are some issues with the functions in Lineshape.py (error checking, not automatically converting sequences to arrays, ...). If this is a way to go I would move the functions to C anyway. Nevertheless a sample function in Python will be provided, so new profiles can easily added without caring about C. I would like to get some feedback whether you think this should be included in numarray. I believe it fits very well into Convolve. Example use: import numarray as num import random as ran import Convolve import Convolve.Lineshape as ls resolution = 0.1 fwhm = 0.5 # get some (random) data, i.e. a stick-spectrum x = num.arange(-50, 50+resolution, resolution) y = num.zeros(x.shape, num.Float) for i in range(10): y[ran.randint(0, len(y)-1)] = ran.random() # create lineshape objects g = ls.GaussProfile(num.arange(-10*fwhm, 10*fwhm+resolution, resolution), 1.0) v = ls.VoigtProfile(num.arange(-10*fwhm, 10*fwhm+resolution, resolution), (0.6, 0.6)) # convolute data with profile res_g = Convolve.convolve(y, g(), Convolve.SAME) res_v = Convolve.convolve(y, v(), Convolve.SAME) for i in zip(x, y, res_g, res_v): print "%12.6f %12.6f %12.6f %12.6f" % i I attach an archive of the whole Convolve/ dir here in my local copy. Greetings, Jochen -- Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de Libert?, ?galit?, Fraternit? GnuPG key: 44BCCD8E Sex, drugs and rock-n-roll -------------- next part -------------- A non-text attachment was scrubbed... Name: convolve.tar.gz Type: application/x-gzip Size: 10075 bytes Desc: not available URL: From jmiller at stsci.edu Thu Aug 22 11:27:02 2002 From: jmiller at stsci.edu (Todd Miller) Date: Thu Aug 22 11:27:02 2002 Subject: [Numpy-discussion] numarray, Convolve, and lineshapes References: Message-ID: <3D652CA1.8080602@stsci.edu> Hi Jochen, Your contribution to the Convolve package is a welcome addition provided that you are willing to tighten up your copyrights a little. Doc/unittest.py has an example of an acceptable copyright, where "Python" should technically be replaced by "numarray", but where the intent remains the same: open source under a BSD-like license. Regards, Todd Jochen K?pper wrote: >Looking at Convolve last night I came up with the idea that we often >need to convolute datasets with common profiles, such as Gauss- or >Voigt-lineshapes, for example. > >So tonight I took my old module I had for that purpose apart and put >it as submodule into Convolve. Well, currently it really only supports >Gauss, Lorentz, and Voigt, but the general "framework" to add more >profiles is there. Adding a new one would consist of defining a new >derived class (overall 5 lines of code) and providing a function that >calculates the actual line profile. > >I chose the implementation using functor classes so profiles can be >reused. > >I am aware that there are some issues with the functions in >Lineshape.py (error checking, not automatically converting sequences >to arrays, ...). If this is a way to go I would move the functions to >C anyway. Nevertheless a sample function in Python will be provided, >so new profiles can easily added without caring about C. > >I would like to get some feedback whether you think this should be >included in numarray. I believe it fits very well into Convolve. > > >Example use: > >import numarray as num >import random as ran >import Convolve >import Convolve.Lineshape as ls > >resolution = 0.1 >fwhm = 0.5 > ># get some (random) data, i.e. a stick-spectrum >x = num.arange(-50, 50+resolution, resolution) >y = num.zeros(x.shape, num.Float) >for i in range(10): > y[ran.randint(0, len(y)-1)] = ran.random() > ># create lineshape objects >g = ls.GaussProfile(num.arange(-10*fwhm, 10*fwhm+resolution, resolution), 1.0) >v = ls.VoigtProfile(num.arange(-10*fwhm, 10*fwhm+resolution, resolution), (0.6, 0.6)) > ># convolute data with profile >res_g = Convolve.convolve(y, g(), Convolve.SAME) >res_v = Convolve.convolve(y, v(), Convolve.SAME) >for i in zip(x, y, res_g, res_v): > print "%12.6f %12.6f %12.6f %12.6f" % i > > >I attach an archive of the whole Convolve/ dir here in my local copy. > >Greetings, >Jochen > -- Todd Miller jmiller at stsci.edu STSCI / SSG From jochen at unc.edu Thu Aug 22 11:44:05 2002 From: jochen at unc.edu (Jochen =?iso-8859-1?q?K=FCpper?=) Date: Thu Aug 22 11:44:05 2002 Subject: [Numpy-discussion] numarray, Convolve, and lineshapes In-Reply-To: <3D652CA1.8080602@stsci.edu> References: <3D652CA1.8080602@stsci.edu> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thu, 22 Aug 2002 14:25:37 -0400 Todd Miller wrote: Todd> Your contribution to the Convolve package is a welcome addition Todd> provided that you are willing to tighten up your copyrights a Todd> little. That's fine, no problem. You can assume that I am willing to allow a 'modified BSD'-style license [1] on everything that I'll contribute to numarray. I might still send it to the ml as GPL'ed, because that's what I put all my code under initially. (And if it doesn't go into numarray, I'd probably like to keep it that way.) Todd> open source under a BSD-like license. I don't like "normal" BSD so much because I wish to release most of my code GPL'ed, unless somebody asks. But GPL and "normal" BSD don't get along well. (See [1]) So I'll clean it up a little tonight and check it in, if that's ok with you. Greetings, Jochen Footnotes: [1] http://www.gnu.org/philosophy/license-list.html#ModifiedBSD - -- University of North Carolina phone: +1-919-962-4403 Department of Chemistry phone: +1-919-962-1579 Venable Hall CB#3290 (Kenan C148) fax: +1-919-843-6041 Chapel Hill, NC 27599, USA GnuPG key: 44BCCD8E -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6-cygwin-fcn-1 (Cygwin) Comment: Processed by Mailcrypt and GnuPG iEYEARECAAYFAj1lMK0ACgkQiJ/aUUS8zY7fmgCfd+3XlZSkdGT/tfOpEZEh3bmu jRUAni3NHLtJWsIumxpkO6anLUyonyPF =EUBk -----END PGP SIGNATURE----- From jmiller at stsci.edu Thu Aug 22 12:20:04 2002 From: jmiller at stsci.edu (Todd Miller) Date: Thu Aug 22 12:20:04 2002 Subject: [Numpy-discussion] numarray, Convolve, and lineshapes References: <3D652CA1.8080602@stsci.edu> Message-ID: <3D653911.7050001@stsci.edu> Jochen K?pper wrote: >-----BEGIN PGP SIGNED MESSAGE----- >Hash: SHA1 > >On Thu, 22 Aug 2002 14:25:37 -0400 Todd Miller wrote: > >Todd> Your contribution to the Convolve package is a welcome addition >Todd> provided that you are willing to tighten up your copyrights a >Todd> little. > >That's fine, no problem. > Excellent. > > >You can assume that I am willing to allow a 'modified BSD'-style >license [1] on everything that I'll contribute to numarray. I might > Good. > >still send it to the ml as GPL'ed, because that's what I put all my >code under initially. (And if it doesn't go into numarray, I'd > That's OK. > >probably like to keep it that way.) > >Todd> open source under a BSD-like license. > My mistake here. numarray is already using a modified-BSD-like license. > > >I don't like "normal" BSD so much because I wish to release most of my >code GPL'ed, unless somebody asks. But GPL and "normal" BSD don't get >along well. (See [1]) > To keep open the possibility that numarray might someday be included in Python, we don't want any part of numarray to be GPL'ed. This is a little overkill, because Packages probably wouldn't be on the immediate list of things to submit anyway. Still, it keeps life simple and us out of trouble. > >So I'll clean it up a little tonight and check it in, if that's ok >with you. > Sounds great! > >Greetings, >Jochen > >Footnotes: >[1] http://www.gnu.org/philosophy/license-list.html#ModifiedBSD >- -- >University of North Carolina phone: +1-919-962-4403 >Department of Chemistry phone: +1-919-962-1579 >Venable Hall CB#3290 (Kenan C148) fax: +1-919-843-6041 >Chapel Hill, NC 27599, USA GnuPG key: 44BCCD8E >-----BEGIN PGP SIGNATURE----- >Version: GnuPG v1.0.6-cygwin-fcn-1 (Cygwin) >Comment: Processed by Mailcrypt and GnuPG > >iEYEARECAAYFAj1lMK0ACgkQiJ/aUUS8zY7fmgCfd+3XlZSkdGT/tfOpEZEh3bmu >jRUAni3NHLtJWsIumxpkO6anLUyonyPF >=EUBk >-----END PGP SIGNATURE----- > > > >------------------------------------------------------- >This sf.net email is sponsored by: OSDN - Tired of that same old >cell phone? Get a new here for FREE! >https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 >_______________________________________________ >Numpy-discussion mailing list >Numpy-discussion at lists.sourceforge.net >https://lists.sourceforge.net/lists/listinfo/numpy-discussion > Regards, Todd -- Todd Miller jmiller at stsci.edu STSCI / SSG From jochen at unc.edu Thu Aug 22 16:29:02 2002 From: jochen at unc.edu (Jochen =?iso-8859-1?q?K=FCpper?=) Date: Thu Aug 22 16:29:02 2002 Subject: [Numpy-discussion] numarray: RandomArray2 In-Reply-To: <3D60F247.60603@stsci.edu> References: <3D5F8F5E.9070700@stsci.edu> <3D60F247.60603@stsci.edu> Message-ID: On Mon, 19 Aug 2002 09:27:35 -0400 Todd Miller wrote: Todd> Jochen K?pper wrote: >> Also note the "strange" docstring of range: >> ,---- >> | range(...) >> | range([start,] stop[, step]) -> list of integers >> `---- >> pointing straight toward its behavior. Ok, reworked the docstrings of module RandomArray2 a bit in order to (hopefully) clarify these issues. I have attached a diff, if it is ok I'll check it in. >> So well, maybe someone with insight into RNG's can comment on the, >> mirroring issue? Anybody? Todd> It appears to me that the parameter order of randint again Todd> emulates "range". The fact that random_integers is not Todd> consistent with randint seem OK to me because random_integers Todd> appears to have been written expressly to tailor the calling Todd> sequence of randint. Put a comment about that in the docstring of random_integers. Greetings, Jochen -- University of North Carolina phone: +1-919-962-4403 Department of Chemistry phone: +1-919-962-1579 Venable Hall CB#3290 (Kenan C148) fax: +1-919-843-6041 Chapel Hill, NC 27599, USA GnuPG key: 44BCCD8E -------------- next part -------------- A non-text attachment was scrubbed... Name: RA.diff Type: text/x-patch Size: 17305 bytes Desc: not available URL: From jmiller at stsci.edu Mon Aug 26 07:35:05 2002 From: jmiller at stsci.edu (Todd Miller) Date: Mon Aug 26 07:35:05 2002 Subject: [Numpy-discussion] numarray: RandomArray2 References: <3D5F8F5E.9070700@stsci.edu> <3D60F247.60603@stsci.edu> Message-ID: <3D6A3C3E.2050705@stsci.edu> Jochen K?pper wrote: >On Mon, 19 Aug 2002 09:27:35 -0400 Todd Miller wrote: > >Todd> Jochen K?pper wrote: > >>>Also note the "strange" docstring of range: >>>,---- >>>| range(...) >>>| range([start,] stop[, step]) -> list of integers >>>`---- >>>pointing straight toward its behavior. >>> > >Ok, reworked the docstrings of module RandomArray2 a bit in order to >(hopefully) clarify these issues. I have attached a diff, if it is ok >I'll check it in. > Please do. Todd > >>>So well, maybe someone with insight into RNG's can comment on the, >>>mirroring issue? >>> > >Anybody? > >Todd> It appears to me that the parameter order of randint again >Todd> emulates "range". The fact that random_integers is not >Todd> consistent with randint seem OK to me because random_integers >Todd> appears to have been written expressly to tailor the calling >Todd> sequence of randint. > >Put a comment about that in the docstring of random_integers. > >Greetings, >Jochen > > >------------------------------------------------------------------------ > >? Packages/RandomArray2/build >? Packages/RandomArray2/Lib/ChangeLog >Index: Packages/RandomArray2/Lib/RandomArray2.py >=================================================================== >RCS file: /cvsroot/numpy/numarray/Packages/RandomArray2/Lib/RandomArray2.py,v >retrieving revision 1.3 >diff -u -r1.3 RandomArray2.py >--- Packages/RandomArray2/Lib/RandomArray2.py 16 Aug 2002 10:44:21 -0000 1.3 >+++ Packages/RandomArray2/Lib/RandomArray2.py 22 Aug 2002 22:11:16 -0000 >@@ -5,6 +5,11 @@ > import math > from types import * > >+__doc__ = """Random number array generators. >+ >+This module provides functions to generate arrays of random numbers. >+""" >+ > # Extended RandomArray to provide more distributions: > # normal, beta, chi square, F, multivariate normal, > # exponential, binomial, multinomial >@@ -13,8 +18,8 @@ > ArgumentError = "ArgumentError" > > def seed(x=0,y=0): >- """seed(x, y), set the seed using the integers x, y; >- Set a random one from clock if y == 0 >+ """Set the RNG seed using the integers x, y; >+ If |y| == 0 set a random one from clock. > """ > if type (x) != IntType or type (y) != IntType : > raise ArgumentError, "seed requires integer arguments." >@@ -30,14 +35,14 @@ > seed() > > def get_seed(): >- "Return the current seed pair" >+ """Return the current seed pair""" > return ranlib.get_seeds() > > def _build_random_array(fun, args, shape=[]): >-# Build an array by applying function fun to >-# the arguments in args, creating an array with >-# the specified shape. >-# Allows an integer shape n as a shorthand for (n,). >+ """Build an array by applying function |fun| to the arguments in >+ |args|, creating an array with the specified shape. >+ Allows an integer shape n as a shorthand for (n,). >+ """ > if isinstance(shape, IntType): > shape = [shape] > if len(shape) != 0: >@@ -51,20 +56,28 @@ > return s[0] > > def random(shape=[]): >- "random(n) or random([n, m, ...]) returns array of random numbers" >+ """random(n) or random([n, m, ...]) >+ >+ Returns array of random numbers in the range 0.0 to 1.0. >+ """ > return _build_random_array(ranlib.sample, (), shape) > > def uniform(minimum, maximum, shape=[]): >- """uniform(minimum, maximum, shape=[]) returns array of given shape of random reals >- in given range""" >+ """uniform([minimum,], maximum[, shape]) >+ >+ Return array with shape |shape| of random Floats with all values >+ > minimum and < maximum. >+ """ > return minimum + (maximum-minimum)*random(shape) > > def randint(minimum, maximum=None, shape=[]): >- """randint(min, max, shape=[]) = random integers >=min, < max >- If max not given, random integers >= 0, + """randint([minimum,] maximum[, shape]) >+ >+ Return random integers >= mininimum, < maximum, >+ if maximum not given, random integers >= 0, < minimum. >+ """ > if maximum is None: >- maximum = minimum >- minimum = 0 >+ maximum, minimum = minimum, 0 > a = Numeric.floor(uniform(minimum, maximum, shape)) > if isinstance(a, Numeric.ArrayType): > return a.astype(Numeric.Int32) >@@ -72,79 +85,94 @@ > return int(a) > > def random_integers(maximum, minimum=1, shape=[]): >- """random_integers(max, min=1, shape=[]) = random integers in range min-max inclusive""" >+ """Return array of random integers in interval [minimum, maximum] >+ >+ Note that this function has reversed arguments. It is simply a >+ redirection through randint, and use of that function (randint) is >+ suggested. >+ """ > return randint(minimum, maximum+1, shape) > > def permutation(n): >- "permutation(n) = a permutation of indices range(n)" >+ """A permutation of indices range(n)""" > return Numeric.argsort(random(n)) > > def standard_normal(shape=[]): >- """standard_normal(n) or standard_normal([n, m, ...]) returns array of >- random numbers normally distributed with mean 0 and standard >- deviation 1""" >+ """standard_normal(n) or standard_normal([n, m, ...]) >+ >+ Returns array of random numbers normally distributed with mean 0 >+ and standard deviation 1. >+ """ > return _build_random_array(ranlib.standard_normal, (), shape) > > def normal(mean, std, shape=[]): >- """normal(mean, std, n) or normal(mean, std, [n, m, ...]) returns >- array of random numbers randomly distributed with specified mean and >- standard deviation""" >- s = standard_normal(shape) >- return s * std + mean >+ """normal(mean, std, n) or normal(mean, std, [n, m, ...]) >+ >+ Returns array of random numbers randomly distributed with >+ specified mean and standard deviation >+ """ >+ s = standard_normal(shape) >+ return s * std + mean > > def multivariate_normal(mean, cov, shape=[]): >- """multivariate_normal(mean, cov) or multivariate_normal(mean, cov, [m, n, ...]) >- returns an array containing multivariate normally distributed random numbers >- with specified mean and covariance. >- >- mean must be a 1 dimensional array. cov must be a square two dimensional >- array with the same number of rows and columns as mean has elements. >- >- The first form returns a single 1-D array containing a multivariate >- normal. >- >- The second form returns an array of shape (m, n, ..., cov.getshape()[0]). >- In this case, output[i,j,...,:] is a 1-D array containing a multivariate >- normal.""" >- # Check preconditions on arguments >- mean = Numeric.array(mean) >- cov = Numeric.array(cov) >- if len(mean.getshape()) != 1: >- raise ArgumentError, "mean must be 1 dimensional." >- if (len(cov.getshape()) != 2) or (cov.getshape()[0] != cov.getshape()[1]): >- raise ArgumentError, "cov must be 2 dimensional and square." >- if mean.getshape()[0] != cov.getshape()[0]: >- raise ArgumentError, "mean and cov must have same length." >- # Compute shape of output >- if isinstance(shape, IntType): shape = [shape] >- final_shape = list(shape[:]) >- final_shape.append(mean.getshape()[0]) >- # Create a matrix of independent standard normally distributed random >- # numbers. The matrix has rows with the same length as mean and as >- # many rows are necessary to form a matrix of shape final_shape. >- x = ranlib.standard_normal(Numeric.multiply.reduce(final_shape)) >- x.setshape(Numeric.multiply.reduce(final_shape[0:len(final_shape)-1]), >- mean.getshape()[0]) >- # Transform matrix of standard normals into matrix where each row >- # contains multivariate normals with the desired covariance. >- # Compute A such that matrixmultiply(transpose(A),A) == cov. >- # Then the matrix products of the rows of x and A has the desired >- # covariance. Note that sqrt(s)*v where (u,s,v) is the singular value >- # decomposition of cov is such an A. >- (u,s,v) = LinearAlgebra2.singular_value_decomposition(cov) >- x = Numeric.matrixmultiply(x*Numeric.sqrt(s),v) >- # The rows of x now have the correct covariance but mean 0. Add >- # mean to each row. Then each row will have mean mean. >- Numeric.add(mean,x,x) >- x.setshape(final_shape) >- return x >+ """multivariate_normal(mean, cov) or multivariate_normal(mean, cov, [m, n, ...]) >+ >+ Returns an array containing multivariate normally distributed >+ random numbers with specified mean and covariance. >+ >+ |mean| must be a one-dimensional array. |cov| must be a square >+ two-dimensional array with the same number of rows and columns as >+ |mean| has elements. >+ >+ The first form returns a single 1-D array containing a >+ multivariate normal. >+ >+ The second form returns an array of shape (m, n, ..., >+ cov.getshape()[0]). In this case, output[i,j,...,:] is a 1-D array >+ containing a multivariate normal. >+ """ >+ # Check preconditions on arguments >+ mean = Numeric.array(mean) >+ cov = Numeric.array(cov) >+ if len(mean.getshape()) != 1: >+ raise ArgumentError, "mean must be 1 dimensional." >+ if (len(cov.getshape()) != 2) or (cov.getshape()[0] != cov.getshape()[1]): >+ raise ArgumentError, "cov must be 2 dimensional and square." >+ if mean.getshape()[0] != cov.getshape()[0]: >+ raise ArgumentError, "mean and cov must have same length." >+ # Compute shape of output >+ if isinstance(shape, IntType): shape = [shape] >+ final_shape = list(shape[:]) >+ final_shape.append(mean.getshape()[0]) >+ # Create a matrix of independent standard normally distributed random >+ # numbers. The matrix has rows with the same length as mean and as >+ # many rows are necessary to form a matrix of shape final_shape. >+ x = ranlib.standard_normal(Numeric.multiply.reduce(final_shape)) >+ x.setshape(Numeric.multiply.reduce(final_shape[0:len(final_shape)-1]), >+ mean.getshape()[0]) >+ # Transform matrix of standard normals into matrix where each row >+ # contains multivariate normals with the desired covariance. >+ # Compute A such that matrixmultiply(transpose(A),A) == cov. >+ # Then the matrix products of the rows of x and A has the desired >+ # covariance. Note that sqrt(s)*v where (u,s,v) is the singular value >+ # decomposition of cov is such an A. >+ (u,s,v) = LinearAlgebra2.singular_value_decomposition(cov) >+ x = Numeric.matrixmultiply(x*Numeric.sqrt(s),v) >+ # The rows of x now have the correct covariance but mean 0. Add >+ # mean to each row. Then each row will have mean mean. >+ Numeric.add(mean,x,x) >+ x.setshape(final_shape) >+ return x > > def exponential(mean, shape=[]): >- """exponential(mean, n) or exponential(mean, [n, m, ...]) returns array >- of random numbers exponentially distributed with specified mean""" >- # If U is a random number uniformly distributed on [0,1], then >- # -ln(U) is exponentially distributed with mean 1, and so >- # -ln(U)*M is exponentially distributed with mean M. >+ """exponential(mean, n) or exponential(mean, [n, m, ...]) >+ >+ Returns array of random numbers exponentially distributed with >+ specified mean >+ """ >+ # If U is a random number uniformly distributed on [0,1], then >+ # -ln(U) is exponentially distributed with mean 1, and so >+ # -ln(U)*M is exponentially distributed with mean M. > x = random(shape) > Numeric.log(x, x) > Numeric.subtract(0.0, x, x) >@@ -160,52 +188,79 @@ > return _build_random_array(ranlib.gamma, (a, r), shape) > > def F(dfn, dfd, shape=[]): >- """F(dfn, dfd) or F(dfn, dfd, [n, m, ...]) returns array of F distributed random numbers with dfn degrees of freedom in the numerator and dfd degrees of freedom in the denominator.""" >+ """F(dfn, dfd) or F(dfn, dfd, [n, m, ...]) >+ >+ Returns array of F distributed random numbers with dfn degrees of >+ freedom in the numerator and dfd degrees of freedom in the >+ denominator. >+ """ > return ( chi_square(dfn, shape) / dfn) / ( chi_square(dfd, shape) / dfd) > > def noncentral_F(dfn, dfd, nconc, shape=[]): >- """noncentral_F(dfn, dfd, nonc) or noncentral_F(dfn, dfd, nonc, [n, m, ...]) returns array of noncentral F distributed random numbers with dfn degrees of freedom in the numerator and dfd degrees of freedom in the denominator, and noncentrality parameter nconc.""" >+ """noncentral_F(dfn, dfd, nonc) or noncentral_F(dfn, dfd, nonc, [n, m, ...]) >+ >+ Returns array of noncentral F distributed random numbers with dfn >+ degrees of freedom in the numerator and dfd degrees of freedom in >+ the denominator, and noncentrality parameter nconc. >+ """ > return ( noncentral_chi_square(dfn, nconc, shape) / dfn ) / ( chi_square(dfd, shape) / dfd ) > > def chi_square(df, shape=[]): >- """chi_square(df) or chi_square(df, [n, m, ...]) returns array of chi squared distributed random numbers with df degrees of freedom.""" >+ """chi_square(df) or chi_square(df, [n, m, ...]) >+ >+ Returns array of chi squared distributed random numbers with df >+ degrees of freedom. >+ """ > return _build_random_array(ranlib.chisquare, (df,), shape) > > def noncentral_chi_square(df, nconc, shape=[]): >- """noncentral_chi_square(df, nconc) or chi_square(df, nconc, [n, m, ...]) returns array of noncentral chi squared distributed random numbers with df degrees of freedom and noncentrality parameter.""" >+ """noncentral_chi_square(df, nconc) or chi_square(df, nconc, [n, m, ...]) >+ >+ Returns array of noncentral chi squared distributed random numbers >+ with df degrees of freedom and noncentrality parameter. >+ """ > return _build_random_array(ranlib.noncentral_chisquare, (df, nconc), shape) > > def binomial(trials, p, shape=[]): >- """binomial(trials, p) or binomial(trials, p, [n, m, ...]) returns array of binomially distributed random integers. >+ """binomial(trials, p) or binomial(trials, p, [n, m, ...]) >+ >+ Returns array of binomially distributed random integers. > >- trials is the number of trials in the binomial distribution. >- p is the probability of an event in each trial of the binomial distribution.""" >+ |trials| is the number of trials in the binomial distribution. >+ |p| is the probability of an event in each trial of the binomial >+ distribution. >+ """ > return _build_random_array(ranlib.binomial, (trials, p), shape) > > def negative_binomial(trials, p, shape=[]): >- """negative_binomial(trials, p) or negative_binomial(trials, p, [n, m, ...]) returns >- array of negative binomially distributed random integers. >+ """negative_binomial(trials, p) or negative_binomial(trials, p, [n, m, ...]) >+ >+ Returns array of negative binomially distributed random integers. > >- trials is the number of trials in the negative binomial distribution. >- p is the probability of an event in each trial of the negative binomial distribution.""" >+ |trials| is the number of trials in the negative binomial >+ distribution. |p| is the probability of an event in each trial of >+ the negative binomial distribution. >+ """ > return _build_random_array(ranlib.negative_binomial, (trials, p), shape) > > def multinomial(trials, probs, shape=[]): >- """multinomial(trials, probs) or multinomial(trials, probs, [n, m, ...]) returns >- array of multinomial distributed integer vectors. >+ """multinomial(trials, probs) or multinomial(trials, probs, [n, m, ...]) >+ >+ Returns array of multinomial distributed integer vectors. >+ >+ |trials| is the number of trials in each multinomial distribution. >+ |probs| is a one dimensional array. There are len(prob)+1 events. >+ prob[i] is the probability of the i-th event, 0<=i+ probability of event len(prob) is 1.-Numeric.sum(prob). > >- trials is the number of trials in each multinomial distribution. >- probs is a one dimensional array. There are len(prob)+1 events. >- prob[i] is the probability of the i-th event, 0<=i- The probability of event len(prob) is 1.-Numeric.sum(prob). >- >- The first form returns a single 1-D array containing one multinomially >- distributed vector. >- >- The second form returns an array of shape (m, n, ..., len(probs)). >- In this case, output[i,j,...,:] is a 1-D array containing a multinomially >- distributed integer 1-D array.""" >- # Check preconditions on arguments >+ The first form returns a single 1-D array containing one >+ multinomially distributed vector. >+ >+ The second form returns an array of shape (m, n, ..., len(probs)). >+ In this case, output[i,j,...,:] is a 1-D array containing a >+ multinomially distributed integer 1-D array. >+ """ >+ # Check preconditions on arguments > probs = Numeric.array(probs) > if len(probs.getshape()) != 1: > raise ArgumentError, "probs must be 1 dimensional." >@@ -215,14 +270,18 @@ > final_shape.append(probs.getshape()[0]+1) > x = ranlib.multinomial(trials, probs.astype(Numeric.Float32), > Numeric.multiply.reduce(shape)) >- # Change its shape to the desire one >+ # Change its shape to the desire one > x.setshape(final_shape) > return x > > def poisson(mean, shape=[]): >- """poisson(mean) or poisson(mean, [n, m, ...]) returns array of poisson >- distributed random integers with specifed mean.""" >+ """poisson(mean) or poisson(mean, [n, m, ...]) >+ >+ Returns array of poisson distributed random integers with specifed >+ mean. >+ """ > return _build_random_array(ranlib.poisson, (mean,), shape) >+ > > def test(): > import test as _test >Index: Packages/RandomArray2/Lib/__init__.py >=================================================================== >RCS file: /cvsroot/numpy/numarray/Packages/RandomArray2/Lib/__init__.py,v >retrieving revision 1.1 >diff -u -r1.1 __init__.py >--- Packages/RandomArray2/Lib/__init__.py 21 Jun 2002 18:25:29 -0000 1.1 >+++ Packages/RandomArray2/Lib/__init__.py 22 Aug 2002 22:11:16 -0000 >@@ -2,3 +2,6 @@ > > from RandomArray2 import * > >+__doc__ = RandomArray2.__doc__ + """ >+See RandomArray2.RandomArray2 for more information. >+""" > -- Todd Miller jmiller at stsci.edu STSCI / SSG From gokhman at sphere.math.utsa.edu Tue Aug 27 16:11:04 2002 From: gokhman at sphere.math.utsa.edu (Dr. Dmitry Gokhman) Date: Tue Aug 27 16:11:04 2002 Subject: [Numpy-discussion] tensor ops in dim > 3? Message-ID: I have a rank three n-dim tensor A. For two of the axes I want to perform v^t A v (a quadratic form with scalar output, where v is a vector). The final output should be a vector. I also need to compute the derivative of this with respect to v. This involves symmetrizing and matrix-vector multiplication (2 sym(A)v using two axes of A only, which gives a vector) with the final result being a matrix. Is there something elegant I can do short of extending numpy with fortrash routines? Perhaps something like SciPy's 3-d tensor ops but for n-dim? Thanks in advance for any tips, - d PS One more dumb question: I just installed the ScientificPython-2.4.1 rpm on my reincarnated Mandrake linux machine running python2.2. Do I need to do something to configure it? My scripts aren't finding things (e.g. indexing.py). From oliphant at ee.byu.edu Tue Aug 27 16:38:03 2002 From: oliphant at ee.byu.edu (Travis Oliphant) Date: Tue Aug 27 16:38:03 2002 Subject: [Numpy-discussion] tensor ops in dim > 3? In-Reply-To: Message-ID: > I have a rank three n-dim tensor A. For two of the axes I want to perform > v^t A v (a quadratic form with scalar output, where v is a vector). The > final output should be a vector. I also need to compute the derivative of > this with respect to v. This involves symmetrizing and matrix-vector > multiplication (2 sym(A)v using two axes of A only, which gives a vector) > with the final result being a matrix. > I'm not exactly sure what you mean by a rank three n-dim tensor (in Numeric the rank is the number of dimensions in the array). But, I think you can accomplish what you desire in two different ways: 1) If A has N dimensions and you want to perform the reduction over axis I'll label a1 and a2 (that is a1 is the axis for the v^t*A sum while a2 is the axis for the A*v sum). Then I think this should work (if a2 > a1). ex1 = [Numeric.NewAxis]*(N-1) ex1[a1] = slice(None) ex2 = [Numeric.NewAxis]*N ex2[a2] = slice(None) Nar = Numeric.add.reduce result = Nar(v[ex1]*Nar(A*v[ex2],axis=a2),axis=a1) # I think you need a recent version of Numeric for the axis keyword # to be defined here. Otherwise, just pass a2 and a1 as arguments # without the keyword. 2) Using dot (requires transposing the matrix) as dot only operates over certain dimensions --- I would not try this. -Travis Oliphant From hinsen at cnrs-orleans.fr Wed Aug 28 01:03:04 2002 From: hinsen at cnrs-orleans.fr (Konrad Hinsen) Date: Wed Aug 28 01:03:04 2002 Subject: [Numpy-discussion] tensor ops in dim > 3? In-Reply-To: References: Message-ID: "Dr. Dmitry Gokhman" writes: > I have a rank three n-dim tensor A. For two of the axes I want to perform > v^t A v (a quadratic form with scalar output, where v is a vector). The > final output should be a vector. I also need to compute the derivative of > this with respect to v. This involves symmetrizing and matrix-vector > multiplication (2 sym(A)v using two axes of A only, which gives a vector) > with the final result being a matrix. Whenever dealing with somewhat more complex operations of this time, I think it's best to go back to the basic NumPy functionality rather then figuring out if there happens to be a function that magically does it. In this case, assuming that the first axis of A is the one that is not summed over: sum( sum(A*v[NewAxis, NewAxis, :], -1) * v[NewAxis, :], -1) The idea is to align v with one of the dimensions of A, then multiply elementwise and sum over the common axis. Note that the first (inner) sum leaves a rank-2 array, so for the second multiplication v gets extended to rank-2 only. > PS One more dumb question: I just installed the ScientificPython-2.4.1 rpm > on my reincarnated Mandrake linux machine running python2.2. Do I need to > do something to configure it? My scripts aren't finding things (e.g. > indexing.py). If you took the binary RPM from my site, they might not work correctly with Mandrake, as they were made for RedHat. The source RPM should work with all RPM-based Linux distributions. There is nothing that needs configuring with an RPM. Also note that Scientific is a package, so the correct way to import the indexing module is import Scientific.indexing Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen at cnrs-orleans.fr Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24 Rue Charles Sadron | Fax: +33-2.38.63.15.17 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ France | Nederlands/Francais ------------------------------------------------------------------------------- From paul at pfdubois.com Wed Aug 28 11:19:04 2002 From: paul at pfdubois.com (Paul F Dubois) Date: Wed Aug 28 11:19:04 2002 Subject: [Numpy-discussion] [Announce] Numerical Python 22.0 Message-ID: <000101c24ebf$5dafd640$0a01a8c0@NICKLEBY> Numerical Python release 22.0 is at Sourceforge. A Windows installer and source zip are also available. Version 22.0 a. Changed multiarraymodule functions to accept keywords where documentation implies it through the use of optional variables. Specifically in multiarray: zeros, take, transpose, repeat, set_string_function, cross_correlate. in ufuncobject: reduce and accumulate now take keyword arguments for the optional axis argument. b. Added support for unsigned shorts 'w' and unsigned ints 'u' -- Travis Oliphant with help from Darren Hart and F. Oliver Gathmann. Increased max permissible iterations in SVD for supplied lapack. -- Dubois Recoded RandomArray.randint to try to see if we can work around bug on some platforms. -- Dubois Version 21.3 June 8, 2002 Fixed bugs: [ #557927 ] fixed matrix slice assignment [ #552922 ] added check for correct datatype in .astype() method. Created new API PyArray_ValidType to handle this check here as well as in multiarraymodule.c [ #551808 ] fixed segfault with unicode array (Travis O.) [ #559511 ] MLab.std now works for axis != 0 (Travis O.) [ #542979 ] sum returns exception tuple [ #528328 ] true division operators used to return single precision on division of integers and longs --- now defaults to double precision (but only on int and long division --- still single-precision for ubyte, short, and byte division. [ none ] arange(start, end, step) slightly different near end points than start + arange(0, N)*step where N is the length. [ none ] a = zeros(2,'D'); a[0] = array(0.0+0.6j) would not work. (Assigning a rank-0 array did not work for CFLOAT_setitem or CDOUBLE_setitem. [ 530688 ] Python crash when transposing array (Walter Moreira) Version 21.0 March 13, 2002 Fixed bugs: [ #482603 ] Memory leak in MA/Numeric/Python Reported by Reggie Dugard. Turned out to be *two* memory leaks in one case in a routine in Numeric, array_objectype. (Dubois) [ none ] if vals was a null-array array([]) putmask and put would crash. Fixed with check. [ #469951 ] n = n1[0] gives array which shares dimension of n1 array. This causes bugs if shape of n1 is changed (n didn't used to have it's own dimensions array (Travis Oliphant) [ #514588 ] MLab.cov(x,x) != MLab.cov(x) (Travis Oliphant) [ #518702 ] segfault when invalid typecode for asarray (Travis Oliphant) [ #497530 ] MA __getitem__ prevents 0 len arrays (Reggie Duggard) [ #508363 ] outerproduct of noncontiguous arrays (Martin Wiechert) [ #513010 ] memory leak in comparisons (Byran Nollett) [ #512223 ] Character typecode not defined (Jochen Kupper) [ #500784 ] MLab.py diff error (anonymous, fixed by Dubois) [ #503741 ] accuracy of MLab.std(x) (Katsunori Waragai) [ #507568 ] overlapping copy a[2:5] = a[3:6] Change uses of memcpy to memmove which allows overlaps. [ numpy-Patches-499722 ] size of buffer created from array is bad (Michel Sanner). [ #502186 ] a BUG in RandomArray.normal (introduced by last bug fix in 20.3) (Katsunori Waragai). Fixed errors for Mac (Jack Jensen). Make rpm's properly, better Windows installers. (Gerard Vermeulen) Added files setup.cfg; setup calculates rpm_install.sh to use current Python. New setup.py, eliminate setup_all.py. Use os.path.join everywhere. Revision in b6 added file README.RPM, further improvements. Implement true division operations for Python 2.2. (Bruce Sherwood) Note: true division of all integer types results in an array of floats, not doubles. This decision is arbitrary and there are arguments either way, so users of this new feature should be aware that the decision may change in the future. New functions in Numeric; they work on any sequence a that can be converted to a Numeric array. Similar change to average in MA. (Dubois) def rank (a): "Get the rank of a (the number of dimensions, not a matrix rank)" def shape (a): "Get the shape of a" def size (a, axis=None): "Get the number of elements in a, or along a certain axis." def average (a, axis=0, weights=None, returned = 0): """average(a, axis=0, weights=None) Computes average along indicated axis. If axis is None, average over the entire array. Inputs can be integer or floating types; result is type Float. If weights are given, result is: sum(a*weights)/(sum(weights)) weights must have a's shape or be the 1-d with length the size of a in the given axis. Integer weights are converted to Float. Not supplying weights is equivalent to supply weights that are all 1. If returned, return a tuple: the result and the sum of the weights or count of values. The shape of these two results will be the same. raises ZeroDivisionError if appropriate when result is scalar. (The version in MA does not -- it returns masked values). """ From histed at MIT.EDU Wed Aug 7 17:02:18 2002 From: histed at MIT.EDU (Mark Histed) Date: Wed Aug 7 17:02:18 2002 Subject: [Numpy-discussion] more functions for MLab.py: find, unique, union, intersect, etc. Message-ID: <200208072353.TAA03451@melbourne-city-street.mit.edu> I've written some glue functions along the lines of what's in MLab.py: find unique union intersect setdiff setxor Quick questions: * any opinions on the algorithms used? * are these worth adding to MLab.py? If so, do I need to provide documentation updates? I can send this as a patch to MLab.py too. * Does anyone have opinions on what to do about the optional outputs from matlab functions? Is it worth trying to provide index matrices as second arguments, for example? If so, any opinions on implementation? a matlab user trying to get started with Numeric, Mark -------------- next part -------------- from Numeric import * # Notes: # I've used the existing MLab.py documentation conventions, not the pydoc # (PEP 256) ones. # # Optional arguments: Most of matlab's functions return 1 or more optional # arguments. I'm not sure what to do here, we could add a keyword argument # to each python function that is a flag specifying # whether or not to return the optional arguments. # Right now we return only the first result # def __tovector(M): """Convert an input array to a vector""" return (resize(M, (multiply.reduce(shape(M)),))) def find(M): """find(M) returns the indices where non-zero values occur in the input matrix. If M is a matrix, it is reshaped to a vector. Note that the indices returned are python-style (0...length-1) rather than Matlab-style (1...length).""" V = __tovector(M) return compress(M, arange(0,len(V))) ## Set functions # Notes: # unique is implemented by sorting the vectors first. The algorithm # is N*log(N) in speed (due to the sorting) and linear in N in # memory usage. Anyone have better ideas? You can use # equal.outer(N,N) but that's N^2 in both memory usage and speed. # ismember uses equal.outer and is thus linear in the sizes of both # vectors in terms of both speed and memory. If the vectors are of # equal size, that means the algorithm is N^2 in the size of the # vectors. This may be acceptable because the second vector is # generally much smaller than the first. There are probably better # ways to do it but my brain is tired. # # Index matrices as second arguments: see notes about optional arguments # above. def unique(N): """unique(N) returns a vector containing the same values as in N but with all repetitions removed. The result is sorted.""" # Matlab's unique accepts an N-d matrix but reshapes it to be a vector. # Also, Matlab's function always sorts. Nsort = sort(__tovector(N)) return concatenate(([Nsort[0]], compress(not_equal(Nsort[:-1], Nsort[1:]), Nsort[1:]))) def ismember(V,S): """ismember(V,S) returns a vector the same size as V containing 1 where the corresponding element of V is in the set S, and 0 otherwise.""" assert(len(shape(V)) == 1, 'First argument must be a vector') return logical_or.reduce(equal.outer(V,S),1) def intersect(M,N): """intersect(M,N) returns a vector whose elements are the elements that occur in both M and N. The result is sorted.""" uM = unique(M) return compress(ismember(uM, unique(N)), uM) def union(M,N): """union(M,N) returns a vector whose elements are the elements that occur in either M or N. The result is sorted.""" return unique(concatenate((M,N))) def setdiff(M,N): """setdiff(M,N) returns a vector containing all the elements of M that are not in N. The result is sorted.""" uM = unique(M) return compress(logical_not(ismember(uM, unique(N))), uM) def setxor(M,N): """setxor(M,N) returns a vector containing all the elements in the union of M and N that are not in the intersection of M and N. The result is sorted.""" return setdiff(union(M,N), intersect(M,N)) From Cath.Lawrence at anu.edu.au Wed Aug 7 20:18:01 2002 From: Cath.Lawrence at anu.edu.au (Cath Lawrence) Date: Wed Aug 7 20:18:01 2002 Subject: [Numpy-discussion] Newbie MA question Message-ID: <439BDEC6-AA7D-11D6-B128-00039390F614@anu.edu.au> Hi, I'm not sure this is the right list - looking at the archives you guys look more like developers more than users. Any pointers to the proper place, or TFMs to R, are welcome. (Yes, I have & have read the Numerical Python documentation.) That said, I'm trying to use masked arrays (for a bioinformatics app calculating stats on distances between pairs of amino acids, if you want to know) and am having a little trouble printing. One possible bug - "x.__str__()" and "x.__repr__()" show different typecodes. Example: >>> import MA >>> id = MA.identity(20) >>> r = MA.ones((20,20))*1.0 >>> rm = MA.MaskedArray(r, mask=id) >>> rm # ie, call x.__repr__() array(data = array (20,20) , type = d, has 400 elements, mask = array (20,20) , type = 1, has 400 elements, fill_value=[ 1.00000002e+20,]) >>> print rm # ie, call x.__str__() array (20,20) , type = O, has 400 elements >>> Secondly, I can't see how to make this print the whole thing if I want it. Which I do; all my matrices are 20*20 'cause there are 20 amino acids. The Numeric.array2string method can't be used because the data is always masked. The best I've found so far is to make a Numeric array by filling with an impossible number like -1, then use array2string. But visually it would be nicer to see the masked values as "--". Thanks for any help, regards, Cath Cath Lawrence, Cath.Lawrence at anu.edu.au Scientific Programmer, Centre for Bioinformation Science, John Curtin School of Medical Research Australian National University, Canberra ACT 0200 ph: Maths (02) 6125 2904; JCSMR (02) 6125 0417; mobile: 0421-902694 fax: (02) 61254712 From reggie at merfinllc.com Thu Aug 8 10:10:03 2002 From: reggie at merfinllc.com (Reggie Dugard) Date: Thu Aug 8 10:10:03 2002 Subject: [Numpy-discussion] Newbie MA question In-Reply-To: <439BDEC6-AA7D-11D6-B128-00039390F614@anu.edu.au> References: <439BDEC6-AA7D-11D6-B128-00039390F614@anu.edu.au> Message-ID: <1028826573.3624.8.camel@auk> Cath, The simple answer to your question is to use MA.set_print_limit(0) to change the behavior of str and repr back to the standard Numeric behavior of always printing the entire array. Then you will get the whole array, with the masked values as '--'. Reggie > Hi, > > I'm not sure this is the right list - looking at the archives you guys > look more like developers more than users. > > Any pointers to the proper place, or TFMs to R, are welcome. (Yes, I > have & have read the Numerical Python documentation.) > > That said, I'm trying to use masked arrays (for a bioinformatics app > calculating stats on distances between pairs of amino acids, if you want > to know) and am having a little trouble printing. > > One possible bug - "x.__str__()" and "x.__repr__()" show different > typecodes. > Example: > >>> import MA > >>> id = MA.identity(20) > >>> r = MA.ones((20,20))*1.0 > >>> rm = MA.MaskedArray(r, mask=id) > >>> rm # ie, call x.__repr__() > array(data = > array (20,20) , type = d, has 400 elements, > mask = > array (20,20) , type = 1, has 400 elements, > fill_value=[ 1.00000002e+20,]) > > >>> print rm # ie, call x.__str__() > array (20,20) , type = O, has 400 elements > >>> > > Secondly, I can't see how to make this print the whole thing if I want > it. Which I do; all my matrices are 20*20 'cause there are 20 amino > acids. > > The Numeric.array2string method can't be used because the data is always > masked. > The best I've found so far is to make a Numeric array by filling with an > impossible number like -1, then use array2string. But visually it would > be nicer to see the masked values as "--". > > Thanks for any help, > regards, > Cath > Cath Lawrence, Cath.Lawrence at anu.edu.au > Scientific Programmer, Centre for Bioinformation Science, > John Curtin School of Medical Research > Australian National University, Canberra ACT 0200 > ph: Maths (02) 6125 2904; JCSMR (02) 6125 0417; > mobile: 0421-902694 fax: (02) 61254712 > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Numpy-discussion mailing list > Numpy-discussion at lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/numpy-discussion From bryan.cole at teraview.co.uk Fri Aug 9 08:52:19 2002 From: bryan.cole at teraview.co.uk (bryan cole) Date: Fri Aug 9 08:52:19 2002 Subject: [Numpy-discussion] floating point exceptions Message-ID: <1028908341.14048.51.camel@bryan.teraviewhq.local> I've just ported a Numeric+Python program from windows to linux and I'm generating floating point exceptions in the linux version which did not occur in windows. I'm trying to generate a gaussian distribution by: Input = Numeric.arange(-1024,1024)/20.0 Output = Numeric.exp(-(Input**2)) At the edges of the distribution the largish negative arguments cause the f.p. exception and prevent calculation of the entire array. On windows the underflow errors are presumably rounded down to 0.0 automatically. Is it possible to get this behaviour on linux/ix86? Anyone got any suggestions on a workarround for this? I see the numpy docs suggest using Masked Arrays, but since I don't know in advance which array items will generate the exceptions, I don't know which items to mask. Can the MA module generate an array mask based on f.p. exceptions from a calculation? any suggestions would be much appreciated. Bryan -- Bryan Cole Teraview Ltd., 302-304 Cambridge Science Park, Milton Road, Cambridge CB4 0WG, United Kingdom. tel: +44 (1223) 435380 / 435386 (direct-dial) fax: +44 (1223) 435382 From bryan.cole at teraview.co.uk Fri Aug 9 09:21:04 2002 From: bryan.cole at teraview.co.uk (bryan cole) Date: Fri Aug 9 09:21:04 2002 Subject: [Numpy-discussion] floating point exceptions In-Reply-To: <1028908341.14048.51.camel@bryan.teraviewhq.local> References: <1028908341.14048.51.camel@bryan.teraviewhq.local> Message-ID: <1028910157.15155.57.camel@bryan.teraviewhq.local> OK, I've worked out how to do this with MA. I mask the Numeric array input to MA.exp() using MA.masked_outside( ... ,-700, 700) then convert the result back to a Numeric array using MA.filled( ..., 0.0) then continue as normal. I'm still interested if there's a more elegant approach. Bryan On Fri, 2002-08-09 at 16:52, bryan cole wrote: > I've just ported a Numeric+Python program from windows to linux and I'm > generating floating point exceptions in the linux version which did not > occur in windows. > > I'm trying to generate a gaussian distribution by: > > Input = Numeric.arange(-1024,1024)/20.0 > Output = Numeric.exp(-(Input**2)) > > At the edges of the distribution the largish negative arguments cause > the f.p. exception and prevent calculation of the entire array. > > On windows the underflow errors are presumably rounded down to 0.0 > automatically. Is it possible to get this behaviour on linux/ix86? > > Anyone got any suggestions on a workarround for this? I see the numpy > docs suggest using Masked Arrays, but since I don't know in advance > which array items will generate the exceptions, I don't know which items > to mask. Can the MA module generate an array mask based on f.p. > exceptions from a calculation? > > any suggestions would be much appreciated. > > Bryan > > > -- > Bryan Cole > Teraview Ltd., 302-304 Cambridge Science Park, Milton Road, Cambridge > CB4 0WG, United Kingdom. > tel: +44 (1223) 435380 / 435386 (direct-dial) fax: +44 (1223) 435382 > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Numpy-discussion mailing list > Numpy-discussion at lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/numpy-discussion -- Bryan Cole Teraview Ltd., 302-304 Cambridge Science Park, Milton Road, Cambridge CB4 0WG, United Kingdom. tel: +44 (1223) 435380 / 435386 (direct-dial) fax: +44 (1223) 435382 From james.analytis at physics.ox.ac.uk Sun Aug 11 16:01:02 2002 From: james.analytis at physics.ox.ac.uk (James G Analytis) Date: Sun Aug 11 16:01:02 2002 Subject: [Numpy-discussion] QR algorithms in Python Message-ID: <200208120000.00948.james.analytis@physics.ox.ac.uk> Hi, I'm looking for a QR algorithm that can decompose complex matrices. The LinearAlgebra package from Numeric doesn't seem to have it. SciPy's linalg package is still on the way, so I can't use that either. Matfunc's QR decomposition only works for real matrices. This problem came up two years ago on this same discussion panel, and Konrad Hinsen recommended that the user download PyLapack from ftp://dirac.cnrs-orleans.fr/pub/ I cannot compile PyLapack because I get this problem: [analytis at toomey Modules]$ python2 compile.py Copy Misc/Makefile.pre.in from the Python distribution to this directory and try again. make: Makefile.pre.in: No such file or directory make: *** No rule to make target `Makefile.pre.in'. Stop. make: *** No targets specified and no makefile found. Stop. [analytis at toomey Modules]$ I think the Makefile searched for is one from an earlier version of Numeric (the tar file is 2yrs old). Any suggestions? Cheers, James From nwagner at mecha.uni-stuttgart.de Mon Aug 12 00:59:02 2002 From: nwagner at mecha.uni-stuttgart.de (Nils Wagner) Date: Mon Aug 12 00:59:02 2002 Subject: [Numpy-discussion] Scientific data - Reading files Message-ID: <3D576C60.13F75D35@mecha.uni-stuttgart.de> Hi, I have collected acceleration data by a multi-channel data acquisition system. Each file (E1431A*.DAT) contains one column with real numbers. The contents of the i-th file should be stored in the i-th row of a data matrix A. How can I manage this task efficiently ? Are there suitable python modules for this purpose ? A small example would be appreciated. Nils From pearu at cens.ioc.ee Mon Aug 12 01:06:04 2002 From: pearu at cens.ioc.ee (Pearu Peterson) Date: Mon Aug 12 01:06:04 2002 Subject: [Numpy-discussion] QR algorithms in Python In-Reply-To: <200208120000.00948.james.analytis@physics.ox.ac.uk> Message-ID: On Mon, 12 Aug 2002, James G Analytis wrote: > Hi, > I'm looking for a QR algorithm that can decompose complex matrices. The > LinearAlgebra package from Numeric doesn't seem to have it. SciPy's linalg > package is still on the way, so I can't use that either. Try SciPy's linalg package again (from CVS), the QR functions is working now: >>> from scipy import linalg >>> from Numeric import dot >>> q,r=linalg.qr([[1,2],[3j,4]]) >>> print q [[-0.31622777+0.j -0.78935222-0.52623481j] [ 0. -0.9486833j -0.1754116 +0.26311741j]] >>> print r [[-3.16227766+0.j -0.63245553+3.79473319j] [ 0. +0.j -2.28035085+0.j ]] >>> print dot(q,r) [[ 1. +0.00000000e+00j 2. -8.71264866e-16j] [ 0. +3.00000000e+00j 4. +3.09051829e-16j]] Regards, Pearu From hinsen at cnrs-orleans.fr Mon Aug 12 06:01:03 2002 From: hinsen at cnrs-orleans.fr (Konrad Hinsen) Date: Mon Aug 12 06:01:03 2002 Subject: [Numpy-discussion] floating point exceptions In-Reply-To: <1028908341.14048.51.camel@bryan.teraviewhq.local> References: <1028908341.14048.51.camel@bryan.teraviewhq.local> Message-ID: bryan cole writes: > I'm trying to generate a gaussian distribution by: > > Input = Numeric.arange(-1024,1024)/20.0 > Output = Numeric.exp(-(Input**2)) > > At the edges of the distribution the largish negative arguments cause > the f.p. exception and prevent calculation of the entire array. > > On windows the underflow errors are presumably rounded down to 0.0 > automatically. Is it possible to get this behaviour on linux/ix86? Yes, rebuild the Python interpreter (not NumPy!) and add the compilation option "-lieee". Alternatively, download and install the current development version of Python from the CVS server (I haven't tried it, but it is supposed to fix this problem as well). Ultimately the problem is in the C standard library. On some platforms it signals underflow as an overflow error, on others it doesn't. Python thus has to get work around such problems in a platform-specific way. Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen at cnrs-orleans.fr Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24 Rue Charles Sadron | Fax: +33-2.38.63.15.17 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ France | Nederlands/Francais ------------------------------------------------------------------------------- From hinsen at cnrs-orleans.fr Mon Aug 12 06:04:01 2002 From: hinsen at cnrs-orleans.fr (Konrad Hinsen) Date: Mon Aug 12 06:04:01 2002 Subject: [Numpy-discussion] QR algorithms in Python In-Reply-To: <200208120000.00948.james.analytis@physics.ox.ac.uk> References: <200208120000.00948.james.analytis@physics.ox.ac.uk> Message-ID: James G Analytis writes: > I cannot compile PyLapack because I get this problem: > > [analytis at toomey Modules]$ python2 compile.py > Copy Misc/Makefile.pre.in from the Python distribution > to this directory and try again. > make: Makefile.pre.in: No such file or directory The old module compilation procedure via Makefile.pre.in does not exist any more in Python 2.2. If and when I find the time, I'll write a distutils script for PyLapack. Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen at cnrs-orleans.fr Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24 Rue Charles Sadron | Fax: +33-2.38.63.15.17 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ France | Nederlands/Francais ------------------------------------------------------------------------------- From Chris.Barker at noaa.gov Mon Aug 12 12:16:08 2002 From: Chris.Barker at noaa.gov (Chris Barker) Date: Mon Aug 12 12:16:08 2002 Subject: [Numpy-discussion] Scientific data - Reading files References: <3D576C60.13F75D35@mecha.uni-stuttgart.de> Message-ID: <3D57F995.958A9E75@noaa.gov> Nils Wagner wrote: > Each file (E1431A*.DAT) contains > one column with real numbers. The contents of the i-th file should be > stored in the i-th row of a data matrix A. Are the files binary or ASCI ? if ASCI, look in Scipy, there are a couple of modules for this kind of thing, I doubt any of them are set up for multiple files, so you'll have to loop through the file list. If binary, you can do something like: while row < NumRows: file = open(filename,'rb') A[row,:] = fromstring(file.read(),Float) # make sure you get the typecode right! file.close() row += 1 WARNING: not the least bit tested. -Chris -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov From james.analytis at physics.ox.ac.uk Tue Aug 13 04:36:03 2002 From: james.analytis at physics.ox.ac.uk (James G Analytis) Date: Tue Aug 13 04:36:03 2002 Subject: [Numpy-discussion] QR algorithms in Python In-Reply-To: References: Message-ID: <200208131235.05006.james.analytis@physics.ox.ac.uk> Dear Pearu, SciPy's linalg modules are just what I need. However, I get the following problem on importing SciPy: [analytis at toomey analytis]$ python2 Python 2.2 (#1, Apr 12 2002, 15:29:57) [GCC 2.96 20000731 (Red Hat Linux 7.2 2.96-109)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import scipy exceptions.ImportError: /usr/lib/python2.2/site-packages/scipy/linalg/flapack.so : undefined symbol: sgesdd_ exceptions.ImportError: /usr/lib/python2.2/site-packages/scipy/linalg/_flinalg.s o: undefined symbol: dlaswp_ Traceback (most recent call last): File "", line 1, in ? File "/tmp/SciPyTest/linux2/lib/python2.2/site-packages/scipy/__init__.py", li ne 42, in ? File "/usr/lib/python2.2/site-packages/scipy/special/__init__.py", line 328, i n ? import orthogonal File "/usr/lib/python2.2/site-packages/scipy/special/orthogonal.py", line 59, in ? from scipy.linalg import eig File "/tmp/SciPyTest/linux2/lib/python2.2/site-packages/scipy/linalg/__init__. py", line 40, in ? File "/tmp/SciPyTest/linux2/lib/python2.2/site-packages/scipy/linalg/basic.py" , line 17, in ? ImportError: /usr/lib/python2.2/site-packages/scipy/linalg/calc_lwork.so: undefi ned symbol: ieeeck_ >>> I am running standard Red Hat 7.3 with a smp kernel, on a dual-processor PIII. Is there anything I should watch out for (compiler issues perhaps)? I appreciate the help! Cheers, James On Monday 12 Aug 2002 9:04 am, Pearu Peterson wrote: > On Mon, 12 Aug 2002, James G Analytis wrote: > > Hi, > > I'm looking for a QR algorithm that can decompose complex matrices. The > > LinearAlgebra package from Numeric doesn't seem to have it. SciPy's > > linalg package is still on the way, so I can't use that either. > > Try SciPy's linalg package again (from CVS), the QR functions is working > > now: > >>> from scipy import linalg > >>> from Numeric import dot > >>> q,r=linalg.qr([[1,2],[3j,4]]) > >>> print q > > [[-0.31622777+0.j -0.78935222-0.52623481j] > [ 0. -0.9486833j -0.1754116 +0.26311741j]] > > >>> print r > > [[-3.16227766+0.j -0.63245553+3.79473319j] > [ 0. +0.j -2.28035085+0.j ]] > > >>> print dot(q,r) > > [[ 1. +0.00000000e+00j 2. -8.71264866e-16j] > [ 0. +3.00000000e+00j 4. +3.09051829e-16j]] > > Regards, > Pearu From nwagner at mecha.uni-stuttgart.de Tue Aug 13 04:53:02 2002 From: nwagner at mecha.uni-stuttgart.de (Nils Wagner) Date: Tue Aug 13 04:53:02 2002 Subject: [Numpy-discussion] QR algorithms in Python References: <200208131235.05006.james.analytis@physics.ox.ac.uk> Message-ID: <3D58F4A9.BFE43265@mecha.uni-stuttgart.de> James G Analytis schrieb: > > Dear Pearu, > SciPy's linalg modules are just what I need. However, I get the following > problem on importing SciPy: > ATLAS is also required. http://math-atlas.sourceforge.net/ Nils > [analytis at toomey analytis]$ python2 > Python 2.2 (#1, Apr 12 2002, 15:29:57) > [GCC 2.96 20000731 (Red Hat Linux 7.2 2.96-109)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import scipy > exceptions.ImportError: > /usr/lib/python2.2/site-packages/scipy/linalg/flapack.so : undefined > symbol: sgesdd_ > exceptions.ImportError: > /usr/lib/python2.2/site-packages/scipy/linalg/_flinalg.s o: undefined > symbol: dlaswp_ > Traceback (most recent call last): > File "", line 1, in ? > File "/tmp/SciPyTest/linux2/lib/python2.2/site-packages/scipy/__init__.py", > li ne 42, in ? > File "/usr/lib/python2.2/site-packages/scipy/special/__init__.py", line 328, > i n ? > import orthogonal > File "/usr/lib/python2.2/site-packages/scipy/special/orthogonal.py", line > 59, in ? > from scipy.linalg import eig > File > "/tmp/SciPyTest/linux2/lib/python2.2/site-packages/scipy/linalg/__init__. > py", line 40, in ? > File > "/tmp/SciPyTest/linux2/lib/python2.2/site-packages/scipy/linalg/basic.py" > , line 17, in ? > ImportError: /usr/lib/python2.2/site-packages/scipy/linalg/calc_lwork.so: > undefi ned symbol: ieeeck_ > >>> > > I am running standard Red Hat 7.3 with a smp kernel, on a dual-processor PIII. > Is there anything I should watch out for (compiler issues perhaps)? > I appreciate the help! > Cheers, > James > > On Monday 12 Aug 2002 9:04 am, Pearu Peterson wrote: > > On Mon, 12 Aug 2002, James G Analytis wrote: > > > Hi, > > > I'm looking for a QR algorithm that can decompose complex matrices. The > > > LinearAlgebra package from Numeric doesn't seem to have it. SciPy's > > > linalg package is still on the way, so I can't use that either. > > > > Try SciPy's linalg package again (from CVS), the QR functions is working > > > > now: > > >>> from scipy import linalg > > >>> from Numeric import dot > > >>> q,r=linalg.qr([[1,2],[3j,4]]) > > >>> print q > > > > [[-0.31622777+0.j -0.78935222-0.52623481j] > > [ 0. -0.9486833j -0.1754116 +0.26311741j]] > > > > >>> print r > > > > [[-3.16227766+0.j -0.63245553+3.79473319j] > > [ 0. +0.j -2.28035085+0.j ]] > > > > >>> print dot(q,r) > > > > [[ 1. +0.00000000e+00j 2. -8.71264866e-16j] > > [ 0. +3.00000000e+00j 4. +3.09051829e-16j]] > > > > Regards, > > Pearu > > ------------------------------------------------------- > This sf.net email is sponsored by: Dice - The leading online job board > for high-tech professionals. Search and apply for tech jobs today! > http://seeker.dice.com/seeker.epl?rel_code1 > _______________________________________________ > Numpy-discussion mailing list > Numpy-discussion at lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/numpy-discussion From paul at pfdubois.com Thu Aug 15 11:41:01 2002 From: paul at pfdubois.com (Paul F Dubois) Date: Thu Aug 15 11:41:01 2002 Subject: [Numpy-discussion] [ANNOUNCE] Pyfort 8.2 and video tutorials for Python, Pyfort Message-ID: <000001c2448b$19b1f0b0$0a01a8c0@NICKLEBY> Pyfortran 8.2 is available. The setup bug for Windows is fixed and a -n option has been added to just generate glue code and stop. Video tutorials are now available at http://esg.llnl.gov/cdat/ (go to documentation and tutorials). There are instructions online about how to set up your computer to play these videos. The Linux instructions may or may not work for you; for the moment we recommend viewing from Windows. These tutorials are mostly for CDAT users, but there are two for Pyfort and one short "Introduction to Python". Our most excellent summer student from USC, Tasha Drew, got everything working. From jochen at jochen-kuepper.de Sun Aug 18 14:30:02 2002 From: jochen at jochen-kuepper.de (Jochen =?iso-8859-1?q?K=FCpper?=) Date: Sun Aug 18 14:30:02 2002 Subject: [Numpy-discussion] Re: numarray: RandomArray2 In-Reply-To: <3D5F8F5E.9070700@stsci.edu> References: <3D5F8F5E.9070700@stsci.edu> Message-ID: On Sun, 18 Aug 2002 08:13:18 -0400 Todd Miller wrote: Todd> Jochen K?pper wrote: >> Looking at RandomArray2 I realized that the functions don't do any >> argument checking. Shouldn't uniform for example check at least >> whether ,---- >> | minimum != maximum >> `---- >> or even make sure that maximum > minimum? (Although the result is >> probably "ok" if it isn't.) Something like >> ,---- >> | def uniform(minimum, maximum, shape=[]): >> | """Return array of random Floats in interval ]minimum, maximum[ >> | with shape |shape|. >> | """ >> | if maximum <= minimum: >> | raise ValueError >> | return minimum + (maximum-minimum)*random(shape) >> `---- >> Todd> I am +0 on this. The parameter order emulates "range". Not exactly, currently: ,---- | >>> range(2, -4) | [] | >>> ran.uniform(2, -4) | -2.2346744537353516 `---- That is, if max < min range returns an empty list, whereas uniform comes up with the same result as for (-4, 2) (well, "mirrored"). Also note the "strange" docstring of range: ,---- | range(...) | range([start,] stop[, step]) -> list of integers `---- pointing straight toward its behavior. Todd> While it does look like it will compute the wrong answer if Todd> called incorrectly, that seems unlikely to me. Well, if max>> import RandomArray2 as ran | >>> ran.uniform(1, 1) | 1.0 `---- So well, maybe someone with insight into RNG's can comment on the, mirroring issue? >> Moreover there are some inconsistencies between functions, i.e.: >> ,---- >> | def randint(minimum, maximum=None, shape=[]): >> `---- >> ,---- >> | def random_integers(maximum, minimum=1, shape=[]): >> `---- Todd> It appears to me that the parameter order of randint again Todd> emulates "range". The fact that random_integers is not Todd> consistent with randint seem OK to me because random_integers Todd> appears to have been written expressly to tailor the calling Todd> sequence of randint. Hmm, v.s. Yes, initially I wondered why there are two functions at all. This explanation sounds like "we wanted some help in confusing the users" :)) Todd> Because randint re-defines its parameters depending on whether 1 Todd> or 2 range values are used, as does range, I don't think there Todd> is a completely consistent way to do this. Either we're "wrong" Todd> for the 1 parameter case or the 2 parameter case. The way it is Todd> specified now seems simplest to me, with "minimum" preceding Todd> "maximum", even though it is not strictly the correct name for Todd> the 1 parameter case. What's about ,---- | uniform(limit1, limit2, shape=[]) `---- and then range-like behaviour? But then, what do we return on ,---- | uniform(2, -4) `---- ??? To make it compatible with range, it should be an empty list, no? Your-even-more-confused-ly's, Jochen -- Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de Libert?, ?galit?, Fraternit? GnuPG key: 44BCCD8E Sex, drugs and rock-n-roll From frank.horowitz at csiro.au Sun Aug 18 23:50:01 2002 From: frank.horowitz at csiro.au (Frank Horowitz) Date: Sun Aug 18 23:50:01 2002 Subject: [Numpy-discussion] Pyrex now interfaces with NumPy (old) array internals In-Reply-To: References: Message-ID: <1029739738.8282.7.camel@bonzo> Perhaps this is best left to Greg Ward, but I just thought that I'd point out to the list that Pyrex in the latest version 0.4.1 successfully interfaces with the (original) Numeric array data types. There are examples in both the Demo subdirectory and in the website's FAQ. Another alternative for getting performance, interfacing to C libraries, and even calling Fortran (from Pyrex's Python/C hybrid code). Frank (Choice is Good ;-) Horowitz From jmiller at stsci.edu Mon Aug 19 06:28:09 2002 From: jmiller at stsci.edu (Todd Miller) Date: Mon Aug 19 06:28:09 2002 Subject: [Numpy-discussion] Re: numarray: RandomArray2 References: <3D5F8F5E.9070700@stsci.edu> Message-ID: <3D60F247.60603@stsci.edu> Jochen K?pper wrote: >On Sun, 18 Aug 2002 08:13:18 -0400 Todd Miller wrote: > >Todd> Jochen K?pper wrote: > >>>Looking at RandomArray2 I realized that the functions don't do any >>>argument checking. Shouldn't uniform for example check at least >>>whether ,---- >>>| minimum != maximum >>>`---- >>>or even make sure that maximum > minimum? (Although the result is >>>probably "ok" if it isn't.) Something like >>>,---- >>>| def uniform(minimum, maximum, shape=[]): >>>| """Return array of random Floats in interval ]minimum, maximum[ >>>| with shape |shape|. >>>| """ >>>| if maximum <= minimum: >>>| raise ValueError >>>| return minimum + (maximum-minimum)*random(shape) >>>`---- >>> >Todd> I am +0 on this. The parameter order emulates "range". > >Not exactly, currently: >,---- >| >>> range(2, -4) >| [] >| >>> ran.uniform(2, -4) >| -2.2346744537353516 >`---- >That is, if max < min range returns an empty list, whereas uniform >comes up with the same result as for (-4, 2) (well, "mirrored"). > >Also note the "strange" docstring of range: >,---- >| range(...) >| range([start,] stop[, step]) -> list of integers >`---- >pointing straight toward its behavior. > >Todd> While it does look like it will compute the wrong answer if >Todd> called incorrectly, that seems unlikely to me. > >Well, if maxproblem as long as it is done "consistently". I don't have enough >knowledge of RNG's to understand whether it is a problem (with respect >to randomness) when calls with the right and wrong ordering of min and >max are mixed. > >Thinking about the case min==max I must say it's a very wasted >function call, but no actually big deal: >,---- >| >>> import RandomArray2 as ran >| >>> ran.uniform(1, 1) >| 1.0 >`---- > >So well, maybe someone with insight into RNG's can comment on the, >mirroring issue? > >>>Moreover there are some inconsistencies between functions, i.e.: >>>,---- >>>| def randint(minimum, maximum=None, shape=[]): >>>`---- >>>,---- >>>| def random_integers(maximum, minimum=1, shape=[]): >>>`---- >>> > >Todd> It appears to me that the parameter order of randint again >Todd> emulates "range". The fact that random_integers is not >Todd> consistent with randint seem OK to me because random_integers >Todd> appears to have been written expressly to tailor the calling >Todd> sequence of randint. > >Hmm, > >v.s. > >Yes, initially I wondered why there are two functions at all. This >explanation sounds like "we wanted some help in confusing the >users" :)) > I read it more like: someone wanted to make one particular user happy by giving them the interface they asked for. Since writing random_integers was easy, they did it even though it amounted to a small duplication of effort and interface functionality. But, I'm just speculating. > >Todd> Because randint re-defines its parameters depending on whether 1 >Todd> or 2 range values are used, as does range, I don't think there >Todd> is a completely consistent way to do this. Either we're "wrong" >Todd> for the 1 parameter case or the 2 parameter case. The way it is >Todd> specified now seems simplest to me, with "minimum" preceding >Todd> "maximum", even though it is not strictly the correct name for >Todd> the 1 parameter case. > >What's about >,---- >| uniform(limit1, limit2, shape=[]) >`---- >and then range-like behaviour? > >But then, what do we return on >,---- >| uniform(2, -4) >`---- >??? > Perhaps my intuition about "range" was incorrect, or we're taking the analogy too far. It seems to me that randint is returning random numbers between two limits, and the order of the limits is irrelevant. randint(2,-4) is identical to randint(-4,2). As you have pointed out, this is distinctly different than range. At this point, I'm still unconvinced that the world would be made a better place either by raising an exception or by changing the semantics to return an "empty array". That small change seems just as likely to upset some user as to make another happy. >Your-even-more-confused-ly's, >Jochen > Todd -- Todd Miller jmiller at stsci.edu STSCI / SSG From jochen at unc.edu Mon Aug 19 09:34:02 2002 From: jochen at unc.edu (Jochen =?iso-8859-1?q?K=FCpper?=) Date: Mon Aug 19 09:34:02 2002 Subject: [Numpy-discussion] Re: numarray In-Reply-To: <3D5F9140.6060304@stsci.edu> References: <3D5F9140.6060304@stsci.edu> Message-ID: On Sun, 18 Aug 2002 08:21:20 -0400 Todd Miller wrote: >> The following patch is required for Cygwin: >> >> Index: Src/_chararraymodule.c >> Todd> I'll apply this. Applied. >> ,---- >> | ***************************************************************** >> | Failure in example: >> | array([1, 8, 100, 100], type=Int8) * array([1, 8, 100, -100], type=Int8) >> | from line #1671 of numtest >> | Expected: >> | Warning: Encountered overflow(s) in multiply >> | array([ 1, 64, 127, -128], type=Int8) >> | Got: array([ 1, 64, 127, -128], type=Int8) >> | ***************************************************************** >> `---- Todd> This overflow exception issue came up earlier this year with Todd> IRIX. My guess is that the function int_overflow_error() in Todd> codegenerator.py is not working correctly. The suggested Todd> temporary patch at the time was: [patch against codegenerator.py] Todd> If you try it out and it solves the problem for Cygwin, we Todd> should probably change it universally. No, it doesn't solve the problem. I hope to find some time later this week to look at it. Greetings, Jochen -- University of North Carolina phone: +1-919-962-4403 Department of Chemistry phone: +1-919-962-1579 Venable Hall CB#3290 (Kenan C148) fax: +1-919-843-6041 Chapel Hill, NC 27599, USA GnuPG key: 44BCCD8E From jochen at unc.edu Mon Aug 19 15:54:02 2002 From: jochen at unc.edu (Jochen =?iso-8859-1?q?K=FCpper?=) Date: Mon Aug 19 15:54:02 2002 Subject: [Numpy-discussion] numarray on Cygwin Message-ID: Hi, I could succesfully compile numarray (see numpy.org) on Cygwin (updated last week), using the standard Cygwin python. However many tests fail, due to "missing" overflow or "division by zero" exceptions. I took a quick look at the test-failures of numarray on numpy. The first problem is that we don't get a "Overflow error" warning when it is expected: ,----[Cygwin] | >>> array([1, 8, 100, 100], type=Int8) * array([1, 8, 100, -100], type=Int8) | array([ 1, 64, 127, -128], type=Int8) `---- Whereas on Linux we get ,----[Linux] | >>> array([1, 8, 100, 100], type=Int8) * array([1, 8, 100, -100], type=Int8) | Warning: Encountered overflow(s) in multiply | array([ 1, 64, 127, -128], type=Int8) `---- Is this related to a configuration option of python (--with-sigfpe ?) or a "feature" of the Cygwin libm/libc? Any ideas? Btw, I tried to rebuild python (cvs maint22-release patched for _socket) but got the following errors with the math module (similar for cmath): ,---- | gcc -shared -Wl,--enable-auto-image-base build/temp.cygwin-1.3.12-i686-2.2/mathmodule.o -L/usr/local/lib -L. -lm -lpython2.2 -o build/lib.cygwin-1.3.12-i686-2.2/math.dll | build/temp.cygwin-1.3.12-i686-2.2/mathmodule.o: In function `math_1': | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:57: undefined reference to `PyFPE_counter' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:57: undefined reference to `PyFPE_counter' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:57: undefined reference to `PyFPE_jbuf' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:57: undefined reference to `PyFPE_counter' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:59: undefined reference to `PyFPE_dummy' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:59: undefined reference to `PyFPE_counter' | build/temp.cygwin-1.3.12-i686-2.2/mathmodule.o: In function `math_2': | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:74: undefined reference to `PyFPE_counter' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:74: undefined reference to `PyFPE_counter' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:74: undefined reference to `PyFPE_jbuf' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:74: undefined reference to `PyFPE_counter' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:76: undefined reference to `PyFPE_dummy' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:76: undefined reference to `PyFPE_counter' | build/temp.cygwin-1.3.12-i686-2.2/mathmodule.o: In function `math_ldexp': | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:173: undefined reference to `PyFPE_counter' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:173: undefined reference to `PyFPE_counter' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:173: undefined reference to `PyFPE_jbuf' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:173: undefined reference to `PyFPE_counter' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:175: undefined reference to `PyFPE_dummy' | /home/software/programming/compiler/python/dist/src/Modules/mathmodule.c:175: undefined reference to `PyFPE_counter' | collect2: ld returned 1 exit status | WARNING: building of extension "math" failed: command 'gcc' failed with exit status 1 `---- Greetings, Jochen -- University of North Carolina phone: +1-919-962-4403 Department of Chemistry phone: +1-919-962-1579 Venable Hall CB#3290 (Kenan C148) fax: +1-919-843-6041 Chapel Hill, NC 27599, USA GnuPG key: 44BCCD8E From jochen at unc.edu Tue Aug 20 08:52:04 2002 From: jochen at unc.edu (Jochen =?iso-8859-1?q?K=FCpper?=) Date: Tue Aug 20 08:52:04 2002 Subject: [Numpy-discussion] Cygwin floating point control Message-ID: The following program does not link on Cygwin ,---- | #include | | int main() | { | return(fgetsticky()); | } `---- due to fpgetsticky beeing unresolved. fpgetsticky is declared in /usr/include/ieeefp.h, but I cannot find any library it is defined in. A search on the Cywin site and at google didn't turn up anything for fpgetsticky on Cygwin. (?) Is it implemented? If so, where? If not, is there any substitute I should be using? Greetings, Jochen PS: It would be nice if you could cc me. -- University of North Carolina phone: +1-919-962-4403 Department of Chemistry phone: +1-919-962-1579 Venable Hall CB#3290 (Kenan C148) fax: +1-919-843-6041 Chapel Hill, NC 27599, USA GnuPG key: 44BCCD8E From nhv at cape.com Tue Aug 20 11:47:05 2002 From: nhv at cape.com (Norman Vine) Date: Tue Aug 20 11:47:05 2002 Subject: [Numpy-discussion] RE: Cygwin floating point control In-Reply-To: Message-ID: <037601c2487a$88f717a0$a300a8c0@nhv> Jochen K?pper writes: > >The following program does not link on Cygwin >,---- >| #include >| >| int main() >| { >| return(fgetsticky()); >| } >`---- >due to fpgetsticky beeing unresolved. > >fpgetsticky is declared in /usr/include/ieeefp.h, but I cannot find >any library it is defined in. A search on the Cywin site and at >google didn't turn up anything for fpgetsticky on Cygwin. (?) > >Is it implemented? If so, where? If not, is there any substitute I >should be using? I use this 'home spun' header that I 'hacked' from the BSD sources Not really sure if it is 100% right or if the license allows this to be used in Cygwin 'proper' but ... it seems to work for me HTH Norman -------------- next part -------------- A non-text attachment was scrubbed... Name: fpu.tgz Type: application/x-compressed Size: 2573 bytes Desc: not available URL: From jochen at jochen-kuepper.de Tue Aug 20 19:39:02 2002 From: jochen at jochen-kuepper.de (Jochen =?iso-8859-1?q?K=FCpper?=) Date: Tue Aug 20 19:39:02 2002 Subject: [Numpy-discussion] numarray -- correlate Message-ID: Is there any good reason to not rename Convolve.cross_correlate to correlate? That fits the other names much better. If needed (aka backwards-compatibility to numpy) we could even provide an alias cross_correlate -- probably documented to be deprecated... But since you have to load a separate module anyway, I think we can rename the function just as well. Greetings, Jochen -- Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de Libert?, ?galit?, Fraternit? GnuPG key: 44BCCD8E Sex, drugs and rock-n-roll From jmiller at stsci.edu Wed Aug 21 05:51:02 2002 From: jmiller at stsci.edu (Todd Miller) Date: Wed Aug 21 05:51:02 2002 Subject: [Numpy-discussion] Re: numarray -- correlate References: Message-ID: <3D638C6C.9090703@stsci.edu> Jochen K?pper wrote: >Is there any good reason to not rename Convolve.cross_correlate to >correlate? That fits the other names much better. > I agree. > >If needed (aka backwards-compatibility to numpy) we could even provide >an alias cross_correlate -- probably documented to be deprecated... But >since you have to load a separate module anyway, I think we can rename >the function just as well. > Please do this. > >Greetings, >Jochen > Todd -- Todd Miller jmiller at stsci.edu STSCI / SSG From jochen at jochen-kuepper.de Wed Aug 21 07:12:09 2002 From: jochen at jochen-kuepper.de (Jochen =?iso-8859-1?q?K=FCpper?=) Date: Wed Aug 21 07:12:09 2002 Subject: [Numpy-discussion] Re: numarray -- correlate In-Reply-To: <3D638C6C.9090703@stsci.edu> References: <3D638C6C.9090703@stsci.edu> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Wed, 21 Aug 2002 08:49:48 -0400 Todd Miller wrote: Todd> Jochen K?pper wrote: >> Is there any good reason to not rename Convolve.cross_correlate to >> correlate? That fits the other names much better. >> Todd> I agree. >> >> If needed (aka backwards-compatibility to numpy) we could even provide >> an alias cross_correlate -- probably documented to be deprecated... Do we need this? >> But since you have to load a separate module anyway, I think we can >> rename the function just as well. >> Todd> Please do this. Done. Greetings, Jochen - -- Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de Libert?, ?galit?, Fraternit? GnuPG key: 44BCCD8E Sex, drugs and rock-n-roll -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: Processed by Mailcrypt and GnuPG iD8DBQE9Y58ciJ/aUUS8zY4RAqeBAKCeAjeXmvl01zgU5trFmh6hteeF1wCgvYYY cbmMNmYlVQF5rqPBczBYsq4= =6eTq -----END PGP SIGNATURE----- From jochen at jochen-kuepper.de Wed Aug 21 20:56:02 2002 From: jochen at jochen-kuepper.de (Jochen =?iso-8859-1?q?K=FCpper?=) Date: Wed Aug 21 20:56:02 2002 Subject: [Numpy-discussion] numarray, Convolve, and lineshapes Message-ID: Looking at Convolve last night I came up with the idea that we often need to convolute datasets with common profiles, such as Gauss- or Voigt-lineshapes, for example. So tonight I took my old module I had for that purpose apart and put it as submodule into Convolve. Well, currently it really only supports Gauss, Lorentz, and Voigt, but the general "framework" to add more profiles is there. Adding a new one would consist of defining a new derived class (overall 5 lines of code) and providing a function that calculates the actual line profile. I chose the implementation using functor classes so profiles can be reused. I am aware that there are some issues with the functions in Lineshape.py (error checking, not automatically converting sequences to arrays, ...). If this is a way to go I would move the functions to C anyway. Nevertheless a sample function in Python will be provided, so new profiles can easily added without caring about C. I would like to get some feedback whether you think this should be included in numarray. I believe it fits very well into Convolve. Example use: import numarray as num import random as ran import Convolve import Convolve.Lineshape as ls resolution = 0.1 fwhm = 0.5 # get some (random) data, i.e. a stick-spectrum x = num.arange(-50, 50+resolution, resolution) y = num.zeros(x.shape, num.Float) for i in range(10): y[ran.randint(0, len(y)-1)] = ran.random() # create lineshape objects g = ls.GaussProfile(num.arange(-10*fwhm, 10*fwhm+resolution, resolution), 1.0) v = ls.VoigtProfile(num.arange(-10*fwhm, 10*fwhm+resolution, resolution), (0.6, 0.6)) # convolute data with profile res_g = Convolve.convolve(y, g(), Convolve.SAME) res_v = Convolve.convolve(y, v(), Convolve.SAME) for i in zip(x, y, res_g, res_v): print "%12.6f %12.6f %12.6f %12.6f" % i I attach an archive of the whole Convolve/ dir here in my local copy. Greetings, Jochen -- Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de Libert?, ?galit?, Fraternit? GnuPG key: 44BCCD8E Sex, drugs and rock-n-roll -------------- next part -------------- A non-text attachment was scrubbed... Name: convolve.tar.gz Type: application/x-gzip Size: 10075 bytes Desc: not available URL: From jmiller at stsci.edu Thu Aug 22 11:27:02 2002 From: jmiller at stsci.edu (Todd Miller) Date: Thu Aug 22 11:27:02 2002 Subject: [Numpy-discussion] numarray, Convolve, and lineshapes References: Message-ID: <3D652CA1.8080602@stsci.edu> Hi Jochen, Your contribution to the Convolve package is a welcome addition provided that you are willing to tighten up your copyrights a little. Doc/unittest.py has an example of an acceptable copyright, where "Python" should technically be replaced by "numarray", but where the intent remains the same: open source under a BSD-like license. Regards, Todd Jochen K?pper wrote: >Looking at Convolve last night I came up with the idea that we often >need to convolute datasets with common profiles, such as Gauss- or >Voigt-lineshapes, for example. > >So tonight I took my old module I had for that purpose apart and put >it as submodule into Convolve. Well, currently it really only supports >Gauss, Lorentz, and Voigt, but the general "framework" to add more >profiles is there. Adding a new one would consist of defining a new >derived class (overall 5 lines of code) and providing a function that >calculates the actual line profile. > >I chose the implementation using functor classes so profiles can be >reused. > >I am aware that there are some issues with the functions in >Lineshape.py (error checking, not automatically converting sequences >to arrays, ...). If this is a way to go I would move the functions to >C anyway. Nevertheless a sample function in Python will be provided, >so new profiles can easily added without caring about C. > >I would like to get some feedback whether you think this should be >included in numarray. I believe it fits very well into Convolve. > > >Example use: > >import numarray as num >import random as ran >import Convolve >import Convolve.Lineshape as ls > >resolution = 0.1 >fwhm = 0.5 > ># get some (random) data, i.e. a stick-spectrum >x = num.arange(-50, 50+resolution, resolution) >y = num.zeros(x.shape, num.Float) >for i in range(10): > y[ran.randint(0, len(y)-1)] = ran.random() > ># create lineshape objects >g = ls.GaussProfile(num.arange(-10*fwhm, 10*fwhm+resolution, resolution), 1.0) >v = ls.VoigtProfile(num.arange(-10*fwhm, 10*fwhm+resolution, resolution), (0.6, 0.6)) > ># convolute data with profile >res_g = Convolve.convolve(y, g(), Convolve.SAME) >res_v = Convolve.convolve(y, v(), Convolve.SAME) >for i in zip(x, y, res_g, res_v): > print "%12.6f %12.6f %12.6f %12.6f" % i > > >I attach an archive of the whole Convolve/ dir here in my local copy. > >Greetings, >Jochen > -- Todd Miller jmiller at stsci.edu STSCI / SSG From jochen at unc.edu Thu Aug 22 11:44:05 2002 From: jochen at unc.edu (Jochen =?iso-8859-1?q?K=FCpper?=) Date: Thu Aug 22 11:44:05 2002 Subject: [Numpy-discussion] numarray, Convolve, and lineshapes In-Reply-To: <3D652CA1.8080602@stsci.edu> References: <3D652CA1.8080602@stsci.edu> Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thu, 22 Aug 2002 14:25:37 -0400 Todd Miller wrote: Todd> Your contribution to the Convolve package is a welcome addition Todd> provided that you are willing to tighten up your copyrights a Todd> little. That's fine, no problem. You can assume that I am willing to allow a 'modified BSD'-style license [1] on everything that I'll contribute to numarray. I might still send it to the ml as GPL'ed, because that's what I put all my code under initially. (And if it doesn't go into numarray, I'd probably like to keep it that way.) Todd> open source under a BSD-like license. I don't like "normal" BSD so much because I wish to release most of my code GPL'ed, unless somebody asks. But GPL and "normal" BSD don't get along well. (See [1]) So I'll clean it up a little tonight and check it in, if that's ok with you. Greetings, Jochen Footnotes: [1] http://www.gnu.org/philosophy/license-list.html#ModifiedBSD - -- University of North Carolina phone: +1-919-962-4403 Department of Chemistry phone: +1-919-962-1579 Venable Hall CB#3290 (Kenan C148) fax: +1-919-843-6041 Chapel Hill, NC 27599, USA GnuPG key: 44BCCD8E -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6-cygwin-fcn-1 (Cygwin) Comment: Processed by Mailcrypt and GnuPG iEYEARECAAYFAj1lMK0ACgkQiJ/aUUS8zY7fmgCfd+3XlZSkdGT/tfOpEZEh3bmu jRUAni3NHLtJWsIumxpkO6anLUyonyPF =EUBk -----END PGP SIGNATURE----- From jmiller at stsci.edu Thu Aug 22 12:20:04 2002 From: jmiller at stsci.edu (Todd Miller) Date: Thu Aug 22 12:20:04 2002 Subject: [Numpy-discussion] numarray, Convolve, and lineshapes References: <3D652CA1.8080602@stsci.edu> Message-ID: <3D653911.7050001@stsci.edu> Jochen K?pper wrote: >-----BEGIN PGP SIGNED MESSAGE----- >Hash: SHA1 > >On Thu, 22 Aug 2002 14:25:37 -0400 Todd Miller wrote: > >Todd> Your contribution to the Convolve package is a welcome addition >Todd> provided that you are willing to tighten up your copyrights a >Todd> little. > >That's fine, no problem. > Excellent. > > >You can assume that I am willing to allow a 'modified BSD'-style >license [1] on everything that I'll contribute to numarray. I might > Good. > >still send it to the ml as GPL'ed, because that's what I put all my >code under initially. (And if it doesn't go into numarray, I'd > That's OK. > >probably like to keep it that way.) > >Todd> open source under a BSD-like license. > My mistake here. numarray is already using a modified-BSD-like license. > > >I don't like "normal" BSD so much because I wish to release most of my >code GPL'ed, unless somebody asks. But GPL and "normal" BSD don't get >along well. (See [1]) > To keep open the possibility that numarray might someday be included in Python, we don't want any part of numarray to be GPL'ed. This is a little overkill, because Packages probably wouldn't be on the immediate list of things to submit anyway. Still, it keeps life simple and us out of trouble. > >So I'll clean it up a little tonight and check it in, if that's ok >with you. > Sounds great! > >Greetings, >Jochen > >Footnotes: >[1] http://www.gnu.org/philosophy/license-list.html#ModifiedBSD >- -- >University of North Carolina phone: +1-919-962-4403 >Department of Chemistry phone: +1-919-962-1579 >Venable Hall CB#3290 (Kenan C148) fax: +1-919-843-6041 >Chapel Hill, NC 27599, USA GnuPG key: 44BCCD8E >-----BEGIN PGP SIGNATURE----- >Version: GnuPG v1.0.6-cygwin-fcn-1 (Cygwin) >Comment: Processed by Mailcrypt and GnuPG > >iEYEARECAAYFAj1lMK0ACgkQiJ/aUUS8zY7fmgCfd+3XlZSkdGT/tfOpEZEh3bmu >jRUAni3NHLtJWsIumxpkO6anLUyonyPF >=EUBk >-----END PGP SIGNATURE----- > > > >------------------------------------------------------- >This sf.net email is sponsored by: OSDN - Tired of that same old >cell phone? Get a new here for FREE! >https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 >_______________________________________________ >Numpy-discussion mailing list >Numpy-discussion at lists.sourceforge.net >https://lists.sourceforge.net/lists/listinfo/numpy-discussion > Regards, Todd -- Todd Miller jmiller at stsci.edu STSCI / SSG From jochen at unc.edu Thu Aug 22 16:29:02 2002 From: jochen at unc.edu (Jochen =?iso-8859-1?q?K=FCpper?=) Date: Thu Aug 22 16:29:02 2002 Subject: [Numpy-discussion] numarray: RandomArray2 In-Reply-To: <3D60F247.60603@stsci.edu> References: <3D5F8F5E.9070700@stsci.edu> <3D60F247.60603@stsci.edu> Message-ID: On Mon, 19 Aug 2002 09:27:35 -0400 Todd Miller wrote: Todd> Jochen K?pper wrote: >> Also note the "strange" docstring of range: >> ,---- >> | range(...) >> | range([start,] stop[, step]) -> list of integers >> `---- >> pointing straight toward its behavior. Ok, reworked the docstrings of module RandomArray2 a bit in order to (hopefully) clarify these issues. I have attached a diff, if it is ok I'll check it in. >> So well, maybe someone with insight into RNG's can comment on the, >> mirroring issue? Anybody? Todd> It appears to me that the parameter order of randint again Todd> emulates "range". The fact that random_integers is not Todd> consistent with randint seem OK to me because random_integers Todd> appears to have been written expressly to tailor the calling Todd> sequence of randint. Put a comment about that in the docstring of random_integers. Greetings, Jochen -- University of North Carolina phone: +1-919-962-4403 Department of Chemistry phone: +1-919-962-1579 Venable Hall CB#3290 (Kenan C148) fax: +1-919-843-6041 Chapel Hill, NC 27599, USA GnuPG key: 44BCCD8E -------------- next part -------------- A non-text attachment was scrubbed... Name: RA.diff Type: text/x-patch Size: 17305 bytes Desc: not available URL: From jmiller at stsci.edu Mon Aug 26 07:35:05 2002 From: jmiller at stsci.edu (Todd Miller) Date: Mon Aug 26 07:35:05 2002 Subject: [Numpy-discussion] numarray: RandomArray2 References: <3D5F8F5E.9070700@stsci.edu> <3D60F247.60603@stsci.edu> Message-ID: <3D6A3C3E.2050705@stsci.edu> Jochen K?pper wrote: >On Mon, 19 Aug 2002 09:27:35 -0400 Todd Miller wrote: > >Todd> Jochen K?pper wrote: > >>>Also note the "strange" docstring of range: >>>,---- >>>| range(...) >>>| range([start,] stop[, step]) -> list of integers >>>`---- >>>pointing straight toward its behavior. >>> > >Ok, reworked the docstrings of module RandomArray2 a bit in order to >(hopefully) clarify these issues. I have attached a diff, if it is ok >I'll check it in. > Please do. Todd > >>>So well, maybe someone with insight into RNG's can comment on the, >>>mirroring issue? >>> > >Anybody? > >Todd> It appears to me that the parameter order of randint again >Todd> emulates "range". The fact that random_integers is not >Todd> consistent with randint seem OK to me because random_integers >Todd> appears to have been written expressly to tailor the calling >Todd> sequence of randint. > >Put a comment about that in the docstring of random_integers. > >Greetings, >Jochen > > >------------------------------------------------------------------------ > >? Packages/RandomArray2/build >? Packages/RandomArray2/Lib/ChangeLog >Index: Packages/RandomArray2/Lib/RandomArray2.py >=================================================================== >RCS file: /cvsroot/numpy/numarray/Packages/RandomArray2/Lib/RandomArray2.py,v >retrieving revision 1.3 >diff -u -r1.3 RandomArray2.py >--- Packages/RandomArray2/Lib/RandomArray2.py 16 Aug 2002 10:44:21 -0000 1.3 >+++ Packages/RandomArray2/Lib/RandomArray2.py 22 Aug 2002 22:11:16 -0000 >@@ -5,6 +5,11 @@ > import math > from types import * > >+__doc__ = """Random number array generators. >+ >+This module provides functions to generate arrays of random numbers. >+""" >+ > # Extended RandomArray to provide more distributions: > # normal, beta, chi square, F, multivariate normal, > # exponential, binomial, multinomial >@@ -13,8 +18,8 @@ > ArgumentError = "ArgumentError" > > def seed(x=0,y=0): >- """seed(x, y), set the seed using the integers x, y; >- Set a random one from clock if y == 0 >+ """Set the RNG seed using the integers x, y; >+ If |y| == 0 set a random one from clock. > """ > if type (x) != IntType or type (y) != IntType : > raise ArgumentError, "seed requires integer arguments." >@@ -30,14 +35,14 @@ > seed() > > def get_seed(): >- "Return the current seed pair" >+ """Return the current seed pair""" > return ranlib.get_seeds() > > def _build_random_array(fun, args, shape=[]): >-# Build an array by applying function fun to >-# the arguments in args, creating an array with >-# the specified shape. >-# Allows an integer shape n as a shorthand for (n,). >+ """Build an array by applying function |fun| to the arguments in >+ |args|, creating an array with the specified shape. >+ Allows an integer shape n as a shorthand for (n,). >+ """ > if isinstance(shape, IntType): > shape = [shape] > if len(shape) != 0: >@@ -51,20 +56,28 @@ > return s[0] > > def random(shape=[]): >- "random(n) or random([n, m, ...]) returns array of random numbers" >+ """random(n) or random([n, m, ...]) >+ >+ Returns array of random numbers in the range 0.0 to 1.0. >+ """ > return _build_random_array(ranlib.sample, (), shape) > > def uniform(minimum, maximum, shape=[]): >- """uniform(minimum, maximum, shape=[]) returns array of given shape of random reals >- in given range""" >+ """uniform([minimum,], maximum[, shape]) >+ >+ Return array with shape |shape| of random Floats with all values >+ > minimum and < maximum. >+ """ > return minimum + (maximum-minimum)*random(shape) > > def randint(minimum, maximum=None, shape=[]): >- """randint(min, max, shape=[]) = random integers >=min, < max >- If max not given, random integers >= 0, + """randint([minimum,] maximum[, shape]) >+ >+ Return random integers >= mininimum, < maximum, >+ if maximum not given, random integers >= 0, < minimum. >+ """ > if maximum is None: >- maximum = minimum >- minimum = 0 >+ maximum, minimum = minimum, 0 > a = Numeric.floor(uniform(minimum, maximum, shape)) > if isinstance(a, Numeric.ArrayType): > return a.astype(Numeric.Int32) >@@ -72,79 +85,94 @@ > return int(a) > > def random_integers(maximum, minimum=1, shape=[]): >- """random_integers(max, min=1, shape=[]) = random integers in range min-max inclusive""" >+ """Return array of random integers in interval [minimum, maximum] >+ >+ Note that this function has reversed arguments. It is simply a >+ redirection through randint, and use of that function (randint) is >+ suggested. >+ """ > return randint(minimum, maximum+1, shape) > > def permutation(n): >- "permutation(n) = a permutation of indices range(n)" >+ """A permutation of indices range(n)""" > return Numeric.argsort(random(n)) > > def standard_normal(shape=[]): >- """standard_normal(n) or standard_normal([n, m, ...]) returns array of >- random numbers normally distributed with mean 0 and standard >- deviation 1""" >+ """standard_normal(n) or standard_normal([n, m, ...]) >+ >+ Returns array of random numbers normally distributed with mean 0 >+ and standard deviation 1. >+ """ > return _build_random_array(ranlib.standard_normal, (), shape) > > def normal(mean, std, shape=[]): >- """normal(mean, std, n) or normal(mean, std, [n, m, ...]) returns >- array of random numbers randomly distributed with specified mean and >- standard deviation""" >- s = standard_normal(shape) >- return s * std + mean >+ """normal(mean, std, n) or normal(mean, std, [n, m, ...]) >+ >+ Returns array of random numbers randomly distributed with >+ specified mean and standard deviation >+ """ >+ s = standard_normal(shape) >+ return s * std + mean > > def multivariate_normal(mean, cov, shape=[]): >- """multivariate_normal(mean, cov) or multivariate_normal(mean, cov, [m, n, ...]) >- returns an array containing multivariate normally distributed random numbers >- with specified mean and covariance. >- >- mean must be a 1 dimensional array. cov must be a square two dimensional >- array with the same number of rows and columns as mean has elements. >- >- The first form returns a single 1-D array containing a multivariate >- normal. >- >- The second form returns an array of shape (m, n, ..., cov.getshape()[0]). >- In this case, output[i,j,...,:] is a 1-D array containing a multivariate >- normal.""" >- # Check preconditions on arguments >- mean = Numeric.array(mean) >- cov = Numeric.array(cov) >- if len(mean.getshape()) != 1: >- raise ArgumentError, "mean must be 1 dimensional." >- if (len(cov.getshape()) != 2) or (cov.getshape()[0] != cov.getshape()[1]): >- raise ArgumentError, "cov must be 2 dimensional and square." >- if mean.getshape()[0] != cov.getshape()[0]: >- raise ArgumentError, "mean and cov must have same length." >- # Compute shape of output >- if isinstance(shape, IntType): shape = [shape] >- final_shape = list(shape[:]) >- final_shape.append(mean.getshape()[0]) >- # Create a matrix of independent standard normally distributed random >- # numbers. The matrix has rows with the same length as mean and as >- # many rows are necessary to form a matrix of shape final_shape. >- x = ranlib.standard_normal(Numeric.multiply.reduce(final_shape)) >- x.setshape(Numeric.multiply.reduce(final_shape[0:len(final_shape)-1]), >- mean.getshape()[0]) >- # Transform matrix of standard normals into matrix where each row >- # contains multivariate normals with the desired covariance. >- # Compute A such that matrixmultiply(transpose(A),A) == cov. >- # Then the matrix products of the rows of x and A has the desired >- # covariance. Note that sqrt(s)*v where (u,s,v) is the singular value >- # decomposition of cov is such an A. >- (u,s,v) = LinearAlgebra2.singular_value_decomposition(cov) >- x = Numeric.matrixmultiply(x*Numeric.sqrt(s),v) >- # The rows of x now have the correct covariance but mean 0. Add >- # mean to each row. Then each row will have mean mean. >- Numeric.add(mean,x,x) >- x.setshape(final_shape) >- return x >+ """multivariate_normal(mean, cov) or multivariate_normal(mean, cov, [m, n, ...]) >+ >+ Returns an array containing multivariate normally distributed >+ random numbers with specified mean and covariance. >+ >+ |mean| must be a one-dimensional array. |cov| must be a square >+ two-dimensional array with the same number of rows and columns as >+ |mean| has elements. >+ >+ The first form returns a single 1-D array containing a >+ multivariate normal. >+ >+ The second form returns an array of shape (m, n, ..., >+ cov.getshape()[0]). In this case, output[i,j,...,:] is a 1-D array >+ containing a multivariate normal. >+ """ >+ # Check preconditions on arguments >+ mean = Numeric.array(mean) >+ cov = Numeric.array(cov) >+ if len(mean.getshape()) != 1: >+ raise ArgumentError, "mean must be 1 dimensional." >+ if (len(cov.getshape()) != 2) or (cov.getshape()[0] != cov.getshape()[1]): >+ raise ArgumentError, "cov must be 2 dimensional and square." >+ if mean.getshape()[0] != cov.getshape()[0]: >+ raise ArgumentError, "mean and cov must have same length." >+ # Compute shape of output >+ if isinstance(shape, IntType): shape = [shape] >+ final_shape = list(shape[:]) >+ final_shape.append(mean.getshape()[0]) >+ # Create a matrix of independent standard normally distributed random >+ # numbers. The matrix has rows with the same length as mean and as >+ # many rows are necessary to form a matrix of shape final_shape. >+ x = ranlib.standard_normal(Numeric.multiply.reduce(final_shape)) >+ x.setshape(Numeric.multiply.reduce(final_shape[0:len(final_shape)-1]), >+ mean.getshape()[0]) >+ # Transform matrix of standard normals into matrix where each row >+ # contains multivariate normals with the desired covariance. >+ # Compute A such that matrixmultiply(transpose(A),A) == cov. >+ # Then the matrix products of the rows of x and A has the desired >+ # covariance. Note that sqrt(s)*v where (u,s,v) is the singular value >+ # decomposition of cov is such an A. >+ (u,s,v) = LinearAlgebra2.singular_value_decomposition(cov) >+ x = Numeric.matrixmultiply(x*Numeric.sqrt(s),v) >+ # The rows of x now have the correct covariance but mean 0. Add >+ # mean to each row. Then each row will have mean mean. >+ Numeric.add(mean,x,x) >+ x.setshape(final_shape) >+ return x > > def exponential(mean, shape=[]): >- """exponential(mean, n) or exponential(mean, [n, m, ...]) returns array >- of random numbers exponentially distributed with specified mean""" >- # If U is a random number uniformly distributed on [0,1], then >- # -ln(U) is exponentially distributed with mean 1, and so >- # -ln(U)*M is exponentially distributed with mean M. >+ """exponential(mean, n) or exponential(mean, [n, m, ...]) >+ >+ Returns array of random numbers exponentially distributed with >+ specified mean >+ """ >+ # If U is a random number uniformly distributed on [0,1], then >+ # -ln(U) is exponentially distributed with mean 1, and so >+ # -ln(U)*M is exponentially distributed with mean M. > x = random(shape) > Numeric.log(x, x) > Numeric.subtract(0.0, x, x) >@@ -160,52 +188,79 @@ > return _build_random_array(ranlib.gamma, (a, r), shape) > > def F(dfn, dfd, shape=[]): >- """F(dfn, dfd) or F(dfn, dfd, [n, m, ...]) returns array of F distributed random numbers with dfn degrees of freedom in the numerator and dfd degrees of freedom in the denominator.""" >+ """F(dfn, dfd) or F(dfn, dfd, [n, m, ...]) >+ >+ Returns array of F distributed random numbers with dfn degrees of >+ freedom in the numerator and dfd degrees of freedom in the >+ denominator. >+ """ > return ( chi_square(dfn, shape) / dfn) / ( chi_square(dfd, shape) / dfd) > > def noncentral_F(dfn, dfd, nconc, shape=[]): >- """noncentral_F(dfn, dfd, nonc) or noncentral_F(dfn, dfd, nonc, [n, m, ...]) returns array of noncentral F distributed random numbers with dfn degrees of freedom in the numerator and dfd degrees of freedom in the denominator, and noncentrality parameter nconc.""" >+ """noncentral_F(dfn, dfd, nonc) or noncentral_F(dfn, dfd, nonc, [n, m, ...]) >+ >+ Returns array of noncentral F distributed random numbers with dfn >+ degrees of freedom in the numerator and dfd degrees of freedom in >+ the denominator, and noncentrality parameter nconc. >+ """ > return ( noncentral_chi_square(dfn, nconc, shape) / dfn ) / ( chi_square(dfd, shape) / dfd ) > > def chi_square(df, shape=[]): >- """chi_square(df) or chi_square(df, [n, m, ...]) returns array of chi squared distributed random numbers with df degrees of freedom.""" >+ """chi_square(df) or chi_square(df, [n, m, ...]) >+ >+ Returns array of chi squared distributed random numbers with df >+ degrees of freedom. >+ """ > return _build_random_array(ranlib.chisquare, (df,), shape) > > def noncentral_chi_square(df, nconc, shape=[]): >- """noncentral_chi_square(df, nconc) or chi_square(df, nconc, [n, m, ...]) returns array of noncentral chi squared distributed random numbers with df degrees of freedom and noncentrality parameter.""" >+ """noncentral_chi_square(df, nconc) or chi_square(df, nconc, [n, m, ...]) >+ >+ Returns array of noncentral chi squared distributed random numbers >+ with df degrees of freedom and noncentrality parameter. >+ """ > return _build_random_array(ranlib.noncentral_chisquare, (df, nconc), shape) > > def binomial(trials, p, shape=[]): >- """binomial(trials, p) or binomial(trials, p, [n, m, ...]) returns array of binomially distributed random integers. >+ """binomial(trials, p) or binomial(trials, p, [n, m, ...]) >+ >+ Returns array of binomially distributed random integers. > >- trials is the number of trials in the binomial distribution. >- p is the probability of an event in each trial of the binomial distribution.""" >+ |trials| is the number of trials in the binomial distribution. >+ |p| is the probability of an event in each trial of the binomial >+ distribution. >+ """ > return _build_random_array(ranlib.binomial, (trials, p), shape) > > def negative_binomial(trials, p, shape=[]): >- """negative_binomial(trials, p) or negative_binomial(trials, p, [n, m, ...]) returns >- array of negative binomially distributed random integers. >+ """negative_binomial(trials, p) or negative_binomial(trials, p, [n, m, ...]) >+ >+ Returns array of negative binomially distributed random integers. > >- trials is the number of trials in the negative binomial distribution. >- p is the probability of an event in each trial of the negative binomial distribution.""" >+ |trials| is the number of trials in the negative binomial >+ distribution. |p| is the probability of an event in each trial of >+ the negative binomial distribution. >+ """ > return _build_random_array(ranlib.negative_binomial, (trials, p), shape) > > def multinomial(trials, probs, shape=[]): >- """multinomial(trials, probs) or multinomial(trials, probs, [n, m, ...]) returns >- array of multinomial distributed integer vectors. >+ """multinomial(trials, probs) or multinomial(trials, probs, [n, m, ...]) >+ >+ Returns array of multinomial distributed integer vectors. >+ >+ |trials| is the number of trials in each multinomial distribution. >+ |probs| is a one dimensional array. There are len(prob)+1 events. >+ prob[i] is the probability of the i-th event, 0<=i+ probability of event len(prob) is 1.-Numeric.sum(prob). > >- trials is the number of trials in each multinomial distribution. >- probs is a one dimensional array. There are len(prob)+1 events. >- prob[i] is the probability of the i-th event, 0<=i- The probability of event len(prob) is 1.-Numeric.sum(prob). >- >- The first form returns a single 1-D array containing one multinomially >- distributed vector. >- >- The second form returns an array of shape (m, n, ..., len(probs)). >- In this case, output[i,j,...,:] is a 1-D array containing a multinomially >- distributed integer 1-D array.""" >- # Check preconditions on arguments >+ The first form returns a single 1-D array containing one >+ multinomially distributed vector. >+ >+ The second form returns an array of shape (m, n, ..., len(probs)). >+ In this case, output[i,j,...,:] is a 1-D array containing a >+ multinomially distributed integer 1-D array. >+ """ >+ # Check preconditions on arguments > probs = Numeric.array(probs) > if len(probs.getshape()) != 1: > raise ArgumentError, "probs must be 1 dimensional." >@@ -215,14 +270,18 @@ > final_shape.append(probs.getshape()[0]+1) > x = ranlib.multinomial(trials, probs.astype(Numeric.Float32), > Numeric.multiply.reduce(shape)) >- # Change its shape to the desire one >+ # Change its shape to the desire one > x.setshape(final_shape) > return x > > def poisson(mean, shape=[]): >- """poisson(mean) or poisson(mean, [n, m, ...]) returns array of poisson >- distributed random integers with specifed mean.""" >+ """poisson(mean) or poisson(mean, [n, m, ...]) >+ >+ Returns array of poisson distributed random integers with specifed >+ mean. >+ """ > return _build_random_array(ranlib.poisson, (mean,), shape) >+ > > def test(): > import test as _test >Index: Packages/RandomArray2/Lib/__init__.py >=================================================================== >RCS file: /cvsroot/numpy/numarray/Packages/RandomArray2/Lib/__init__.py,v >retrieving revision 1.1 >diff -u -r1.1 __init__.py >--- Packages/RandomArray2/Lib/__init__.py 21 Jun 2002 18:25:29 -0000 1.1 >+++ Packages/RandomArray2/Lib/__init__.py 22 Aug 2002 22:11:16 -0000 >@@ -2,3 +2,6 @@ > > from RandomArray2 import * > >+__doc__ = RandomArray2.__doc__ + """ >+See RandomArray2.RandomArray2 for more information. >+""" > -- Todd Miller jmiller at stsci.edu STSCI / SSG From gokhman at sphere.math.utsa.edu Tue Aug 27 16:11:04 2002 From: gokhman at sphere.math.utsa.edu (Dr. Dmitry Gokhman) Date: Tue Aug 27 16:11:04 2002 Subject: [Numpy-discussion] tensor ops in dim > 3? Message-ID: I have a rank three n-dim tensor A. For two of the axes I want to perform v^t A v (a quadratic form with scalar output, where v is a vector). The final output should be a vector. I also need to compute the derivative of this with respect to v. This involves symmetrizing and matrix-vector multiplication (2 sym(A)v using two axes of A only, which gives a vector) with the final result being a matrix. Is there something elegant I can do short of extending numpy with fortrash routines? Perhaps something like SciPy's 3-d tensor ops but for n-dim? Thanks in advance for any tips, - d PS One more dumb question: I just installed the ScientificPython-2.4.1 rpm on my reincarnated Mandrake linux machine running python2.2. Do I need to do something to configure it? My scripts aren't finding things (e.g. indexing.py). From oliphant at ee.byu.edu Tue Aug 27 16:38:03 2002 From: oliphant at ee.byu.edu (Travis Oliphant) Date: Tue Aug 27 16:38:03 2002 Subject: [Numpy-discussion] tensor ops in dim > 3? In-Reply-To: Message-ID: > I have a rank three n-dim tensor A. For two of the axes I want to perform > v^t A v (a quadratic form with scalar output, where v is a vector). The > final output should be a vector. I also need to compute the derivative of > this with respect to v. This involves symmetrizing and matrix-vector > multiplication (2 sym(A)v using two axes of A only, which gives a vector) > with the final result being a matrix. > I'm not exactly sure what you mean by a rank three n-dim tensor (in Numeric the rank is the number of dimensions in the array). But, I think you can accomplish what you desire in two different ways: 1) If A has N dimensions and you want to perform the reduction over axis I'll label a1 and a2 (that is a1 is the axis for the v^t*A sum while a2 is the axis for the A*v sum). Then I think this should work (if a2 > a1). ex1 = [Numeric.NewAxis]*(N-1) ex1[a1] = slice(None) ex2 = [Numeric.NewAxis]*N ex2[a2] = slice(None) Nar = Numeric.add.reduce result = Nar(v[ex1]*Nar(A*v[ex2],axis=a2),axis=a1) # I think you need a recent version of Numeric for the axis keyword # to be defined here. Otherwise, just pass a2 and a1 as arguments # without the keyword. 2) Using dot (requires transposing the matrix) as dot only operates over certain dimensions --- I would not try this. -Travis Oliphant From hinsen at cnrs-orleans.fr Wed Aug 28 01:03:04 2002 From: hinsen at cnrs-orleans.fr (Konrad Hinsen) Date: Wed Aug 28 01:03:04 2002 Subject: [Numpy-discussion] tensor ops in dim > 3? In-Reply-To: References: Message-ID: "Dr. Dmitry Gokhman" writes: > I have a rank three n-dim tensor A. For two of the axes I want to perform > v^t A v (a quadratic form with scalar output, where v is a vector). The > final output should be a vector. I also need to compute the derivative of > this with respect to v. This involves symmetrizing and matrix-vector > multiplication (2 sym(A)v using two axes of A only, which gives a vector) > with the final result being a matrix. Whenever dealing with somewhat more complex operations of this time, I think it's best to go back to the basic NumPy functionality rather then figuring out if there happens to be a function that magically does it. In this case, assuming that the first axis of A is the one that is not summed over: sum( sum(A*v[NewAxis, NewAxis, :], -1) * v[NewAxis, :], -1) The idea is to align v with one of the dimensions of A, then multiply elementwise and sum over the common axis. Note that the first (inner) sum leaves a rank-2 array, so for the second multiplication v gets extended to rank-2 only. > PS One more dumb question: I just installed the ScientificPython-2.4.1 rpm > on my reincarnated Mandrake linux machine running python2.2. Do I need to > do something to configure it? My scripts aren't finding things (e.g. > indexing.py). If you took the binary RPM from my site, they might not work correctly with Mandrake, as they were made for RedHat. The source RPM should work with all RPM-based Linux distributions. There is nothing that needs configuring with an RPM. Also note that Scientific is a package, so the correct way to import the indexing module is import Scientific.indexing Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen at cnrs-orleans.fr Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24 Rue Charles Sadron | Fax: +33-2.38.63.15.17 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ France | Nederlands/Francais ------------------------------------------------------------------------------- From paul at pfdubois.com Wed Aug 28 11:19:04 2002 From: paul at pfdubois.com (Paul F Dubois) Date: Wed Aug 28 11:19:04 2002 Subject: [Numpy-discussion] [Announce] Numerical Python 22.0 Message-ID: <000101c24ebf$5dafd640$0a01a8c0@NICKLEBY> Numerical Python release 22.0 is at Sourceforge. A Windows installer and source zip are also available. Version 22.0 a. Changed multiarraymodule functions to accept keywords where documentation implies it through the use of optional variables. Specifically in multiarray: zeros, take, transpose, repeat, set_string_function, cross_correlate. in ufuncobject: reduce and accumulate now take keyword arguments for the optional axis argument. b. Added support for unsigned shorts 'w' and unsigned ints 'u' -- Travis Oliphant with help from Darren Hart and F. Oliver Gathmann. Increased max permissible iterations in SVD for supplied lapack. -- Dubois Recoded RandomArray.randint to try to see if we can work around bug on some platforms. -- Dubois Version 21.3 June 8, 2002 Fixed bugs: [ #557927 ] fixed matrix slice assignment [ #552922 ] added check for correct datatype in .astype() method. Created new API PyArray_ValidType to handle this check here as well as in multiarraymodule.c [ #551808 ] fixed segfault with unicode array (Travis O.) [ #559511 ] MLab.std now works for axis != 0 (Travis O.) [ #542979 ] sum returns exception tuple [ #528328 ] true division operators used to return single precision on division of integers and longs --- now defaults to double precision (but only on int and long division --- still single-precision for ubyte, short, and byte division. [ none ] arange(start, end, step) slightly different near end points than start + arange(0, N)*step where N is the length. [ none ] a = zeros(2,'D'); a[0] = array(0.0+0.6j) would not work. (Assigning a rank-0 array did not work for CFLOAT_setitem or CDOUBLE_setitem. [ 530688 ] Python crash when transposing array (Walter Moreira) Version 21.0 March 13, 2002 Fixed bugs: [ #482603 ] Memory leak in MA/Numeric/Python Reported by Reggie Dugard. Turned out to be *two* memory leaks in one case in a routine in Numeric, array_objectype. (Dubois) [ none ] if vals was a null-array array([]) putmask and put would crash. Fixed with check. [ #469951 ] n = n1[0] gives array which shares dimension of n1 array. This causes bugs if shape of n1 is changed (n didn't used to have it's own dimensions array (Travis Oliphant) [ #514588 ] MLab.cov(x,x) != MLab.cov(x) (Travis Oliphant) [ #518702 ] segfault when invalid typecode for asarray (Travis Oliphant) [ #497530 ] MA __getitem__ prevents 0 len arrays (Reggie Duggard) [ #508363 ] outerproduct of noncontiguous arrays (Martin Wiechert) [ #513010 ] memory leak in comparisons (Byran Nollett) [ #512223 ] Character typecode not defined (Jochen Kupper) [ #500784 ] MLab.py diff error (anonymous, fixed by Dubois) [ #503741 ] accuracy of MLab.std(x) (Katsunori Waragai) [ #507568 ] overlapping copy a[2:5] = a[3:6] Change uses of memcpy to memmove which allows overlaps. [ numpy-Patches-499722 ] size of buffer created from array is bad (Michel Sanner). [ #502186 ] a BUG in RandomArray.normal (introduced by last bug fix in 20.3) (Katsunori Waragai). Fixed errors for Mac (Jack Jensen). Make rpm's properly, better Windows installers. (Gerard Vermeulen) Added files setup.cfg; setup calculates rpm_install.sh to use current Python. New setup.py, eliminate setup_all.py. Use os.path.join everywhere. Revision in b6 added file README.RPM, further improvements. Implement true division operations for Python 2.2. (Bruce Sherwood) Note: true division of all integer types results in an array of floats, not doubles. This decision is arbitrary and there are arguments either way, so users of this new feature should be aware that the decision may change in the future. New functions in Numeric; they work on any sequence a that can be converted to a Numeric array. Similar change to average in MA. (Dubois) def rank (a): "Get the rank of a (the number of dimensions, not a matrix rank)" def shape (a): "Get the shape of a" def size (a, axis=None): "Get the number of elements in a, or along a certain axis." def average (a, axis=0, weights=None, returned = 0): """average(a, axis=0, weights=None) Computes average along indicated axis. If axis is None, average over the entire array. Inputs can be integer or floating types; result is type Float. If weights are given, result is: sum(a*weights)/(sum(weights)) weights must have a's shape or be the 1-d with length the size of a in the given axis. Integer weights are converted to Float. Not supplying weights is equivalent to supply weights that are all 1. If returned, return a tuple: the result and the sum of the weights or count of values. The shape of these two results will be the same. raises ZeroDivisionError if appropriate when result is scalar. (The version in MA does not -- it returns masked values). """