[Numpy-discussion] Who uses matrix?
Robert Hetland
hetland at tamu.edu
Thu May 11 07:16:00 EDT 2006
I never use matrices primarily because I am worried about one more
data type floating around in my code. That is, data is often read in
or constructed as lists, and must be converted to an array to do
anything useful.
Take a simple example of optimal interpolation: Read in the data (as
a list?), construct the background error covariance arrays (arrays),
then do about three lines of linear algebra; e.g.,
W = dot(linalg.inv(B + O), Bi) # weights
A = dot(self.Di,W).transpose() # analysis
Ea = diag(sqrt(self.Be - dot(W.transpose(), Bi))) # analysis
error
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.
Should I give in? If there was some shorthand links to inverse and
transpose methods in the array object, I would definitely stick with
arrays.
-Rob
p.s. By the way, array broadcasting saves much pain in creating the
background error covariance arrays. Yeah for array broadcasting!
-----
Rob Hetland, Assistant Professor
Dept of Oceanography, Texas A&M University
p: 979-458-0096, f: 979-845-6331
e: hetland at tamu.edu, w: http://pong.tamu.edu
More information about the NumPy-Discussion
mailing list