From: Colin J. W. <cj...@sy...> - 2003-12-10 13:31:16
|
Sebastian Haase wrote: >Hi Colin, >We are interested in using your PyMatrix packages (It' numarray not Numeric, >right?). > That is correct. Testing so far is with numarray 0.7. Please remember to also install the version 0.7 addons. When version 0.8 arrives, all will be included in one package. The package is intended for comment and review. There is at least one problem in numarray, which we hope will be resolved in version 0.8. For example, for some functions, upon the first call, the function returns an instance of the M class (matrix), on the second call, it returns an instance of the NumArray class. > First though, someone in my lab had the following concern: >What if I actually need the element-wise multiplication ? >(In other words: The Matlab .* operator) [1] <%5B1%5D> > >I understand that python does not allow to invent new operator symbols. > Yes. This issue was discussed in PEP 225 <http://www.python.org/peps/pep-0225.html>. >How about multiplying a Matrix with a Numarray ? > Please see [2] <#2>. >Is it possible to have a 'numarray view' of a Matrix object ? (I'm thinking >of two differently typed objects sharing one "value-memory space", so that >essentially the type determines which multiplication is being used ...) > There is a need to think through the copy/view approach in PyMatrix. Currently, most cases are copies. I'm inclined to deprecate the dual view approach, but I would appreciate comments. Let me know if you have any questions or comments. Colin W. >Thanks, >Sebastian Haase > > >----- Original Message ----- >From: "Colin J. Williams" <cj...@sy...> >Newsgroups: comp.lang.python,comp.lang.python.announce >To: "numpy-discussion" <num...@li...>; "SciPy >Discussion List" <sci...@sc...> >Cc: "Huaiyu Zhu" <hz...@us...> >Sent: Monday, November 24, 2003 5:17 AM >Subject: [Numpy-discussion] PyMatrix: Announcement > > > > >>PyMatrix is available for test and review. >> http://www3.sympatico.ca/cjw >> >>PyMatrix provides access to basic matrix arithmetic, using Python and >>numarray. >> >>Examples: >> A * B => the product of >>matrices A and B >> A.I => the inverse of matrix >> >> >A > > >> A.EVectors => the eigenvectors of A >> A.var(0) => the variances of the >>columns of A >> (a.T*a).I * a.T*b => the solution (x) for a * >>x = b, >> where a is a >>matrix and b a column vector >> >>This package was developed on a Windows XP. I would appreciate >>comments, particularly with respect to usage on other systems. >> >>Colin W. >> >> >> >> >> >>------------------------------------------------------- >>This SF.net email is sponsored by: SF.net Giveback Program. >>Does SourceForge.net help you be more productive? Does it >>help you create better code? SHARE THE LOVE, and help us help >>YOU! Click Here: http://sourceforge.net/donate/ >>_______________________________________________ >>Numpy-discussion mailing list >>Num...@li... >>https://lists.sourceforge.net/lists/listinfo/numpy-discussion >> >> >> Notes: [1] Elementwise Multiplication The thinking here is that, for most matrix usage, the elementwise multiplication is less frequently required. Thus, a more complex expression can be tolerated. See the example below: a= mRange(9, shape=(3, 3)) b= mRange((9, 18), shape= (3, 3)) print 'Matrixwise multiplation:' print 'a * b (prettyprinted):', pp(a * b) print 'Elementwise multiplation:' print 'a * b (prettyprinted):', pp(M(a.A * b.A))) In the last case, we use the array mechanism. The output is: Matrixwise multiplation: a * b (prettyprinted):matrix([[ 42, 45, 48], [150, 162, 174], [258, 279, 300]]) None Elementwise multiplation: a * b (prettyprinted):matrix([[ 0, 10, 22], [ 36, 52, 70], [ 90, 112, 136]]) None [2] Multiplication of a matrix by an array or nested list When an compatible array or list is juxtapositioned with a matrix, it is in effect coerced to the higher class. a= mRange(9, shape=(3, 3) c= N.arange(9, shape=(3, 3)) print 'A matrix multiplied by an array:' print 'a * c (prettyprinted):', pp(a * c) print 'A matrix multiplied by a list:' lst= [[0, 1, 2], [3, 4, 5], [6, 7, 8]] print 'a * lst (prettyprinted):', pp(a * lst) The output is: A matrix multiplied by an array: a * c (prettyprinted):matrix([[ 15, 18, 21], [ 42, 54, 66], [ 69, 90, 111]]) None A matrix multiplied by a list: a * lst (prettyprinted):matrix([[ 15, 18, 21], [ 42, 54, 66], [ 69, 90, 111]]) None |
From: Perry G. <pe...@st...> - 2003-12-11 19:34:51
|
> -----Original Message----- > From: num...@li... > [mailto:num...@li...]On Behalf Of > Sebastian > Haase > Sent: Thursday, December 11, 2003 1:45 PM > To: Colin J. Williams > Cc: num...@li... > Subject: Re: [Numpy-discussion] PyMatrix: Announcement > > > Thanks for the reply. > PEP 225 is from Sept-2000 and http://matpy.sourceforge.net and > dated from > Mar-2002 (Python 2.0) > > That is about the results I got from my first google-groups > search. What is > the current thinking about this ? > Looks to me like the "new operator" idea is dead. Or ?? > > I actually like (read: could live with) alternative 4 in PEP > 225: which is, > to provide operator overloading for what I call > "different views" of the same matrix / image. How difficult is this to > implement ? > (What is the real difference to alternative 3 ? They both have > m1.E * m2.E > . ) > > Regards, > Sebastian > > > None > If I recall correctly, Guido didn't dismiss it out of hand, but he wasn't going to do anything about it unless there was sufficient noise from the community that this was very important. I think it is, and I suppose if we campaign enough, it may be considered. Perry |
From: Colin J. W. <cj...@sy...> - 2003-12-11 20:45:42
|
Perry Greenfield wrote: >>-----Original Message----- >>From: num...@li... >>[mailto:num...@li...]On Behalf Of >>Sebastian >>Haase >>Sent: Thursday, December 11, 2003 1:45 PM >>To: Colin J. Williams >>Cc: num...@li... >>Subject: Re: [Numpy-discussion] PyMatrix: Announcement >> >> >>Thanks for the reply. >>PEP 225 is from Sept-2000 and http://matpy.sourceforge.net and >>dated from >>Mar-2002 (Python 2.0) >> >>That is about the results I got from my first google-groups >>search. What is >>the current thinking about this ? >>Looks to me like the "new operator" idea is dead. Or ?? >> >>I actually like (read: could live with) alternative 4 in PEP >>225: which is, >>to provide operator overloading for what I call >>"different views" of the same matrix / image. How difficult is this to >>implement ? >>(What is the real difference to alternative 3 ? They both have >>m1.E * m2.E >>. ) >> >>Regards, >>Sebastian >> >> >> None >> >> >> >If I recall correctly, Guido didn't dismiss it out of hand, but he >wasn't going to do anything about it unless there was sufficient >noise from the community that this was very important. I think it >is, and I suppose if we campaign enough, it may be considered. > >Perry > > There has been little clamour for adding this complication to the syntax over the last three plus years. I suggest that PyMatrix shows that the desired results can be achieved, with few additional key strokes and without adding to the Python character set. Colin W |
From: Perry G. <pe...@st...> - 2003-12-11 21:02:10
|
> There has been little clamour for adding this complication to the syntax > over the last three plus years. > This is certainly true. > I suggest that PyMatrix shows that the desired results can be achieved, > with few additional key strokes and without adding to the Python > character set. > > Colin W > I guess I will wait and see. The worry I have is that when people attempt to use a PyMatrix where a numarray is expected (and the same issue would be true for Numeric) that the behavior of expressions may cause some confusion (i.e., since matrix multiplies may happen instead of element-wise operations). This most likely will result in some visible exception (e.g., incompatible shapes) but may not. If people never mix the two, it won't be a problem; or if they are careful to convert before doing so. Perry |