Discussion: Introducing new operators for matrix computation

Huaiyu Zhu hzhu at knowledgetrack.com
Fri Jul 14 20:22:41 EDT 2000


On Fri, 14 Jul 2000 18:10:27 -0600, Bjorn Pettersen <bjorn at roguewave.com> wrote:
>Huaiyu Zhu wrote:
>> 
>> On Fri, 14 Jul 2000 11:38:51 -0600, Bjorn Pettersen <bjorn at roguewave.com>
>> wrote:
>> >
>> >Well, this could actually be generally useful, but not with the .+
>> >syntax (since the dot would interfer with methods on the sequence
>> >object).
>
>You're quoting me out of context here. What I could find generally
>useful is a way to spell component-wise operations...

That's what I meant to quote.  Sorry if that's not clear.


>As you might have guessed, I don't really care what is done in the
>matrix case -- I don't use matrices.  If a component-wise "operator"
>were to be added to Python however, I would expect it to work with e.g.
>list and in that case a dot is ambigous:
>
>  mylist.foo()  # are you calling the foo method on the list or the
>elements?

This is a method call, because f is not an operator and .f is not, either.
Or are you thinking about something else?


>I have a feeling that what you really want these operators to do is
>paralell component-wise operations on more than one collection object
>though, which is exactly what list comprehensions do (in a general way).

How would you write this in list compresension (in less than 10 lines)?

B*(sin(A*x+b).*(A*y)/3)/C

Note that * is matrix multiplication and .* is elementwise.  Note that C is
a matrix so the / is matrixwise.  If you want to write everything as for
loops it takes at least 30 lines, without any decent error analysis.

The main attraction of OO programming for numerical computation is finally
being able to not write out the indices, as mathematicians have always be
able to do on paper.

-- 
Huaiyu Zhu                       hzhu at users.sourceforge.net
Matrix for Python Project        http://MatPy.sourceforge.net 



More information about the Python-list mailing list