[Numpy-discussion] matrix default to column vector?
Alan G Isaac
aisaac at american.edu
Fri Jun 5 13:30:05 EDT 2009
On 6/5/2009 11:38 AM Olivier Verdier apparently wrote:
> I think matrices can be pretty tricky when used for
> teaching. For instance, you have to explain that all the
> operators work component-wise, except the multiplication!
> Another caveat is that since matrices are always 2x2, the
> "scalar product" of two column vectors computed as " x.T
> * y" will not be a scalar, but a 2x2 matrix. There is also
> the fact that you must cast all your vectors to column/raw
> matrices (as in matlab). For all these reasons, I prefer
> to use arrays and dot for teaching, and I have never had
> any complaints.
I do not understand this "argument".
You should take it very seriously when someone
reports to you that the matrix object is a crucial to them,
e.g., as a teaching tool. Even if you do not find
personally persuasive an example like
http://mail.scipy.org/pipermail/numpy-discussion/2009-June/043001.html
I have told you: this is important for my students.
Reporting that your students do not complain about using
arrays instead of matrices does not change this one bit.
Student backgrounds differ by domain of application. In
economics, matrices are in *very* wide use, and
multidimensional arrays get almost no use. Textbooks in
econometrics (a huge and important field, even outside of
economics) are full of proofs using matrix algebra.
A close match to what the students see is crucial.
When working with multiplication or exponentiation,
matrices do what they expect, and 2d arrays do not.
One more point. As Python users we get used to installing
a package here and a package there to add functionality.
But this is not how most people looking for a matrix
language see the world. Removing the matrix object from
NumPy will raise the barrier to adoption by social
scientists, and there should be a strongly persuasive reason
before taking such a step.
Separately from all that, does anyone doubt that there is
code that depends on the matrix object? The core objection
to a past proposal for useful change was that it could break
extant code. I would hope that nobody who took that
position would subsequently propose removing the matrix
object altogether.
Cheers,
Alan Isaac
PS If x and y are "column vectors" (i.e., matrices), then
x.T * y *should* be a 1×1 matrix.
Since the * operator is doing matrix multiplication,
this is the correct result, not an anomaly.
More information about the NumPy-Discussion
mailing list