[Numpy-discussion] matrix default to column vector?
Charles R Harris
Sat Jun 6 15:50:33 CDT 2009
On Sat, Jun 6, 2009 at 2:30 PM, Robert Kern <email@example.com> wrote:
> On Sat, Jun 6, 2009 at 14:59, Alan G Isaac <firstname.lastname@example.org> wrote:
> > On 6/6/2009 2:58 PM Charles R Harris apparently wrote:
> >> How about the common expression
> >> exp((v.t*A*v)/2)
> >> do you expect a matrix exponential here?
> > I take your point that there are conveniences
> > to treating a 1 by 1 matrix as a scalar.
> > Most matrix programming languages do this, I think.
> > For sure GAUSS does. The result of x' * A * x
> > is a "matrix" (it has one row and one column) but
> > it functions like a scalar (and even more,
> > since right multiplication by it is also allowed).
> > While I think this is "wrong", especially in a
> > language that readily distinguishes scalars
> > and matrices, I recognize that many others have
> > found the behavior useful. And I confess that
> > when I talk about quadratic forms, I do treat
> > x.T * A * x as if it were scalar.
> The old idea of introducing RowVector and ColumnVector would help
> here. If x were a ColumnVector and A a Matrix, then you can introduce
> the following rules:
> x.T is a RowVector
> RowVector * ColumnVector is a scalar
> RowVector * Matrix is a RowVector
> Matrix * ColumnVector is a ColumnVector
Yes, that is another good solution. In tensor notation, RowVectors have
signature r_i, ColumnVectors c^i, and matrices M^i_j. The '*' operator is
then a contraction on adjacent indices, a result with no indices is a
scalar, and the only problem that remains is the tensor product usually
achieved by x*y.T. But making the exception that col * row is the tensor
product producing a matrix would solve that and still raise an error for
such things as col*row*row. Or we could simply require something like
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion