[Numpy-discussion] matrix default to column vector?

Skipper Seabold jsseabold@gmail....
Mon Jun 8 14:54:19 CDT 2009


On Mon, Jun 8, 2009 at 3:33 PM, Robert Kern<robert.kern@gmail.com> wrote:
> On Mon, Jun 8, 2009 at 14:10, Alan G Isaac<aisaac@american.edu> wrote:
>>>> 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 know. Honestly, I would prefer that teachers skip over the normal
> equations entirely and move directly to decomposition approaches. If
> you are going to make them implement least-squares from more basic
> tools, I think it's more enlightening as a student to start with the
> SVD than the normal equations.
>
>> 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.  ;-)
>
> If it's not a class where they are going to use what they learn in the
> future to write numerical programs, I really don't care whether you
> teach it with numpy or not.
>
> If it *is* such a class, then I would prefer that the students get
> taught the right way to write numerical programs.
>

I started in such a class (with Dr. Isaac as a matter of fact).  I
found the use of Python with Numpy to be very enlightening for the
basic concepts of linear algebra.  I appreciated the simple syntax of
matrices at the time as a gentler learning curve since my background
in programming was mainly at a hobbyist level.

I then went on to take a few econometrics courses where we learned the
normal equations.  Now a few years later I am working on scipy.stats
as a google summer of code project, and I am learning why a SVD
decomposition is much more efficient (an economist never necessarily
*needs* to know what's under the hood of their stats package).  The
intuition for the numerical methods was in place, as well as the basic
familiarity with numpy/scipy.  So I would not discount this approach
too much.  People get what they want out of anything, and I was happy
to learn about Python and Numpy/Scipy as alternatives to proprietary
packages.  And I hope my work this summer can contribute even a little
to making the project an accessible alternative for researchers
without a strong technical background.

Skipper


More information about the Numpy-discussion mailing list