[Numpy-discussion] adding a .M attribute to the array.

Perry Greenfield perry at stsci.edu
Wed Mar 6 12:49:06 CST 2002

Konrad Hinsen 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).
Not an unreasonable position. Are you also arguing that the two types
should know about each other and raise an exception if there is an
attempt to mix them in operations?


More information about the Numpy-discussion mailing list