[Python-Dev] Infix operators
greg.ewing at canterbury.ac.nz
Fri Jul 25 04:02:30 CEST 2008
Scott Dial wrote:
> Perhaps I'm nobody, but I think this would be ridiculous. Matrices are
> not native objects to the language.
Why should that matter? We already have things like
sum(), which operates on any sequence of numbers,
without needing a special "array of numbers" data
type. I don't see why one shouldn't be able to
perform matrix multiplication on a plausible
representation of a matrix using the existing
built-in sequence types.
> Until a matrix is a first-order object in Python,
> there is no logic to making operators for them.
If there were a dedicated matrix type, there would
actually be *less* reason to have a new operator,
since that type could just implement * as matrix
However, there are disadvantages to that, which
become apparent when numpy is considered. There are
good reasons for wanting * to mean elementwise
multiplication of numpy arrays. There are also
good reasons for wanting to use numpy arrays as
matrices, since you get the benefit of all the
other powerful things that numpy can do with
You can use a matrix type that's based somehow
on a numpy array, but there are problems with that
too. E.g. if you add a matrix and a plain numpy
array, what type should the result be? If plain
numpy arrays can be used directly as matrices, that
problem goes away.
More information about the Python-Dev