[Numpy-discussion] Who uses matrix?

Bill Baxter wbaxter at gmail.com
Tue May 9 22:11:05 EDT 2006


On 5/10/06, Sasha <ndarray at mac.com> wrote:
>
> On 5/9/06, Bill Baxter <wbaxter at gmail.com> wrote:
> >  ..... In linear algebra terms, a 1x1 matrix *is* a scalar for all
> intents and purposes ...
>
> In linear algebra you start with an N-dimensional space V then define
> an NxN dimensional space of matrices M.  [...]
>

All this long introduction was to demonstrate that even from the
> linear algebra point of view a 1x1 matrix (an element of the space
> R'xR) is not the same as a scalar (an element of R).


Ok, fair enough.   I think what I was trying to express is that it's rarely
useful to have such a thing as a 1x1 matrix in linear algebra.   For
instance, I can't recall a single textbook or journal article I've read
where a distinction was made between a true scalar product between two
vectors <x,y> and the 1x1 matrix resulting from the matrix product of, x^t *
y.  But I'll admit that most of what I read is more like applied math than
pure math.  On the other hand, I would expect that most people trying to
write programs to do actual calculations are also going to be more
interested in practical applications of math than math theory.

Also, if you want to get nit-picky about what is correct in terms of
rigorous math, it rasies the question as to whether it even makes any sense
to apply .sum() to an element of R^n x R^m.   In the end Numpy is a package
for performing practical computations.  So the question shouldn't be whether
a 1x1 matrix is really the same thing as a scalar or not, but which way is
going to make life the easiest for the people writing the code.  Currently
numpy lets you multiply a 1x1 matrix times another matrix as if the 1x1 were
a scalar.  That seems like a practical and useful behavior to me, regardless
of its correctness.

Anyway, back to sum -- if .sum() is to return a scalar, then what about
.sum(axis=0)?   Should that be a 1-D array of scalars rather than a matrix?
If you answer no, then what about .sum(axis=0).sum(axis=1)?   (Unrelated
issue, but it seems that .sum(axis=0) and .sum(axis=1) both return row
vectors, whereas I would expect the axis=1 variety to be a column vector.)
Anyway, seems to be like Tim (I think) said.  This is just introducing new
inconsistencies in place of old ones, so what's the point.

In numpy, however, algebraic differences between 1x1 matrices and
> scalars are not as important as the fact that matrices are mutable
> while scalars are not.
>

Seems like for most code the lack of methods and attributes on the scalar
would be the bigger deal than the mutability difference.  But either way,
I'm not sure what point you're trying to make there.  Scalars should go away
because 1x1 matrices are more flexible?

Regards,
--bill
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20060509/0e300f44/attachment.html>


More information about the NumPy-Discussion mailing list