[Numpy-discussion] matrix default to column vector?

Alan G Isaac aisaac at american.edu
Mon Jun 8 15:10:37 EDT 2009

>> Going back to Alan Isaac's example:
>> 1)  beta = (X.T*X).I * X.T * Y
>> 2)  beta = np.dot(np.dot(la.inv(np.dot(X.T,X)),X.T),Y)

Robert Kern wrote:
> 4) beta = la.lstsq(X, Y)[0]
> I really hate that example.

Remember, the example is a **teaching** example.
I actually use NumPy in a Master's level math econ course
(among other places).  As it happens, I do get around to
explaining why using an explicit inverse is a bad idea
numerically, but that is entirely an aside in a course
that is not concerned with numerical methods.  It is
concerned only with mastering a few basic math tools,
and being able to implement some of them in code is
largely a check on understanding and precision (and
to provide basic background for future applications).
Having them use lstsq is counterproductive for the
material being covered, at least initially.

A typical course of this type uses Excel or includes
no applications at all.  So please,
show a little gratitude.  ;-)

Alan Isaac

More information about the NumPy-Discussion mailing list