[Numpy-discussion] matrix default to column vector?

Robert Kern robert.kern at gmail.com
Sun Jun 7 15:08:29 EDT 2009

On Sun, Jun 7, 2009 at 07:20, Tom K. <tpk at kraussfamily.org> wrote:
> Olivier Verdier-2 wrote:
>> There would be a much simpler solution than allowing a new operator. Just
>> allow the numpy function dot to take more than two arguments. Then A*B*C
>> in
>> matrix notation would simply be:
>> dot(A,B,C)
>> with arrays. Wouldn't that make everybody happy? Plus it does not break
>> backward compatibility. Am I missing something?
> That wouldn't make me happy because it is not the same syntax as a binary
> infix operator.  Introducing a new operator for matrix multiply (and
> possibly matrix exponentiation) does not break backward compatibility - how
> could it, given that the python language does not yet support the new
> operator?
> 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)
> With a multiple arguments to dot, 2) becomes:
> 3)  beta = np.dot(la.inv(np.dot(X.T, X)), X.T, Y)
> This is somewhat better than 2) but not as nice as 1) IMO.

4) beta = la.lstsq(X, Y)[0]

I really hate that example.

> Seeing 1) with @'s would take some getting used but I think we would adjust.
> For ".I" I would propose that ".I" be added to nd-arrays that inverts each
> matrix of the last two dimensions, so for example if X is 3D then X.I is the
> same as np.array([inv(Xi) for Xi in X]).  This is also backwards compatible.
> With this behavior and the one I proposed for @, by adding preceding
> dimensions we are allowing doing matrix algebra on collections of matrices
> (although it looks like we might need a new .T that just swaps the last two
> dimensions to really pull that off).  But a ".I" attribute and its behavior
> needn't be bundled with whatever proposal we wish to make to the python
> community for a new operator of course.

I am vehemently against adding .I to ndarray. I want to *discourage*
the formation of explicit inverses. It is almost always a very wrong
thing to do.

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco

More information about the NumPy-Discussion mailing list