[Numpy-discussion] Who uses matrix?

Bill Baxter wbaxter at gmail.com
Fri May 12 01:18:01 EDT 2006


On 5/11/06, Robert Hetland <hetland at tamu.edu> wrote:
>
>
> Is it worth it to convert the arrays to matrices in order to do this
> handful of calculation?  Almost.  I covet the shorthand .T notation
> in matrix object while getting RSI typing in t-r-a-n-s-p-o-s-e.
> Also, for involved calculations inverse, transpose et. al are long
> enough words such that the line always wraps, resulting in less-
> readable code.


+1 on a .T shortcut for arrays.
+1 on a .H shortcut for arrays, too.  (Instead of .conj().transpose())

I'm not wild about the .I shortcut.  I prefer to see big expensive
operations like a matrix inverse to stand out a little more when I'm looking
at the code.  And I hardly ever need an inverse anyway (usually an lu_factor
or SVD or something like that will do what I need more efficiently and
robustly than directly taking an inverse).

I just finished writing my first few hundred lines of code using array
instead of matrix.  It went fine.  Here are my impressions: it was nice not
having to worry so much about whether my vectors were row vectors or column
vectors all the time, or whether this or that was matrix type or not.  It
felt much less like I was fighting with numpy than when I was using matrix.
I also ported a little bit of matlab code that was full of apostrophes
(matlab's transpose operator).  With numpy arrays, all but one of the
transposes went away.    I realized also that most of what I end up doing is
wrangling data to get it in the right shape and form so that I can to do
just a few lines of linear algebra on it, similar to what you observe, Rob,
so it makes little sense to have everything be matrices all the time.

So looks like I'm joining the camp of "matrix -- not worth the bother"
folks.  The .T shortcut for arrays would still be nice though.

And some briefer way to make a new axis than 'numpy.newaxis' would be nice
too (I'm trying to keep my global namespace clean these days).
--- Whoa I just noticed that a[None,:] has the same effect as 'newaxis'.  Is
that a blessed way to do things?


Regards,
Bill
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20060512/28aa6058/attachment.html>


More information about the NumPy-Discussion mailing list