From: Konrad H. <hi...@cn...> - 2002-03-06 19:24:48
|
"Perry Greenfield" <pe...@st...> writes: > discussed (and never resolved) a couple years ago. Suppose I do this: > > x = a.M * libfunc(b.M, c.M) > > where libfunc is a 3rd party module written in Python that was written > assuming that operators were elementwise operators. It may silently Then you are calling a routine with wrong arguments - that can happen in Python all the time. From my point of view, arrays and matrices are two entirely different things. A function written for matrix objects cannot be expected to work with array objects, and vice versa. Matrix operations should return matrix objects, and array operations should return array objects. What arrays and matrices have in common is not semantics, but implementation. That is something that implementors should profit from, but users shouldn't even need to know about. The discussion about matrices has focused on matrix multiplication as the main difference between the two objects. I suppose this was motivated by comparisons to Matlab and similar environments, which do not have the notion of data types and thus cannot properly distinguish between matrices and arrays. I don't see why should follow this limited approach. A matrix object should not only do matrix multiplication properly, but also provide methods such as diagonalization, application of functions as matrix functions, etc. That would be much more than syntactic sugar, it would be a real implementation of the mathematical concept "matrix". Seen from this point of view, it is not at all clear why an array should have an attribute that is an "equivalent" matrix, as no such equivalence exists in general (only for 2D arrays). > Conceivably there will be modules useful for both kinds of objects. Do I don't think so. The only analogous operations between arrays and matrices are addition, subtraction, negation, and multiplication with a scalar, and those would use the same syntax anyway. Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hi...@cn... 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 ------------------------------------------------------------------------------- |