[Numpy-discussion] Detect subclass of ndarray
Charles R Harris
charlesr.harris@gmail....
Sat Mar 24 14:15:57 CDT 2007
On 3/24/07, Colin J. Williams <cjw@sympatico.ca> wrote:
>
> Charles R Harris wrote:
> >
> >
> > On 3/24/07, *Alan G Isaac* <aisaac@american.edu
> > <mailto:aisaac@american.edu>> wrote:
> >
> > On Fri, 23 Mar 2007, Charles R Harris apparently wrote:
> > > the following gives the wrong result:
> > > In [15]: I = matrix(eye(2))
> > > In [16]: I*ones(2)
> > > Out[16]: matrix([[ 1., 1.]])
> > > where the output should be a column vector.
> >
> > Why should this output a column?
> > I would prefer an exception.
> > Add the axis if you want it:
> > I*ones(2)[:,None]
> > works fine.
> >
> >
> > Because it is mathematically correct. You can't multiply a vector by a
> > 2x2 matrix and get a 1x2 matrix as the result. Sure, there are work
> > arounds, but if matrix multiplication is going to work when mixed with
> > arrays, it should work correctly.
> >
> > Chuck
> >
> It depends on the convention you use when working with matrices.
>
> Suppose you adopt the notion, for matrices, a vector is always
> represented by a matrix. This a row vector would have the shape (1, n)
> and the column vector would have (n, 1).
>
> If A were a (3, 4) matrix and b were a 4 element column vector, then
> the product of A by b, using matrix arithmetic, would give a 3 element
> column vector.
Yes, that is what I am thinking. Given that there are only the two
possibilities, row or column, choose the only one that is compatible with
the multiplying matrix. The result will not always be a column vector, for
instance, mat([[1]])*ones(3) will be a 1x3 row vector.
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20070324/c5e3a26d/attachment.html
More information about the Numpy-discussion
mailing list