[PEP draft 2] Adding new math operators

Konrad Hinsen hinsen at cnrs-orleans.fr
Fri Aug 11 05:26:01 EDT 2000


hzhu at localhost.localdomain (Huaiyu Zhu) writes:

> The real problem is that the variables happen to come in the flavor suitable
> for the input of your formula, and the output of your formula happen to be
> in a flavor suitable for the rest of your program.  This formula therefore

Which happens to be the case in all situations that I am familiar with.

> >I have never seen any situation in which matrix objects (i.e. objects
> >which are the result of matrix operations) are subsequently used in
> >elementwise operations, with a result that has to be used in a matrix
> >operation immediately afterwards.
> 
> Well, the majority of these cases come from using the "broadcasting rules".
> You compute x and y (two axes) from linear algebra.  You compute a function
> of them using elementwise operation instead of meshdomain as in matlab. Then
> you transform z by linear algebra operations again.  This kind of operations
> are quite common in data visualization, for example.

I have such situations in my own code. I tend to write the function as
a Python function expecting array arguments, thus inside the function
all operations are elementwise. Then I call it from within the
matrix-operation code, adding ".array" to the arguments.

> In statistical computations it is common to switch context of doing
> elementwise computation (ie assuming independence between the components)
> and do full matrix operation (taking into account correlation, etc). 

Sounds familiar as well - and my solution is the same. The statistical
operation is encapsulated in a function or method (as one would do
anyway!), which contains all the matrix operations.

In both of these cases, the "diferent-logic" parts of the code are
complex enough that they would be seen as separate algorithmis steps
and written as functions or methods. This is very different from the
articifial examples you used in which switches between the "array" and
"matrix" point of view occur three times in a single line.
-- 
-------------------------------------------------------------------------------
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
-------------------------------------------------------------------------------



More information about the Python-list mailing list