[Numpy-discussion] defmatrix.py

Charles R Harris charlesr.harris@gmail....
Mon Mar 26 16:43:36 CDT 2007


On 3/26/07, Travis Oliphant <oliphant@ee.byu.edu> wrote:
>
> Charles R Harris wrote:
>
> >
> >
> > On 3/26/07, *Travis Oliphant* <oliphant@ee.byu.edu
> > <mailto:oliphant@ee.byu.edu>> wrote:
> >
> >     Charles R Harris wrote:
> >
> >     >
> >     >
> >     > On 3/26/07, *Nils Wagner* <nwagner@iam.uni-stuttgart.de
> >     <mailto:nwagner@iam.uni-stuttgart.de>
> >     > <mailto: nwagner@iam.uni-stuttgart.de
> >     <mailto:nwagner@iam.uni-stuttgart.de>>> wrote:
> >     >
> >     >     Charles R Harris wrote:
> >     >     >
> >     >     >
> >     >     > On 3/25/07, *Nils Wagner* <nwagner@iam.uni-stuttgart.de
> >     <mailto:nwagner@iam.uni-stuttgart.de>
> >     >     <mailto:nwagner@iam.uni-stuttgart.de
> >     <mailto:nwagner@iam.uni-stuttgart.de>>
> >     >     > <mailto: nwagner@iam.uni-stuttgart.de
> >     <mailto:nwagner@iam.uni-stuttgart.de>
> >     >     <mailto:nwagner@iam.uni-stuttgart.de
> >     <mailto:nwagner@iam.uni-stuttgart.de>>>> wrote:
> >     >     >
> >     >     >     Hi,
> >     >     >
> >     >     >
> >     >
> >     >  <snip>
> >     >
> >     > Ok, things should be working now. In order to get rid of the scipy
> >     > problems I just needed to rm the scipy package in site-packages
> and
> >     > then reinstall.
> >     >
> >     > I still need to figure out a real fix down in the dot routine
> >     because
> >
> >
> >     No, don't fix the dot routine.  Remember the dot routine should
> accept
> >     mixed 2-d arrays and 1-d arrays because it is more general than
> matrix
> >     multiplication.
> >
> >
> > Sure, but it can't return a row vector when multiplying a 1-d vector.
> > It just ain't mathematically possible no matter how the 1-d vector is
> > interpreted. It needs to return either a column vector or a 1-d vector.
>
> Ah.. I see what your point is.
>
> How to fix that.   The problem is choosing the Python type of the output
> array.  It's being selected as matrix right now because of the
> precedence of the matrix subtype, but it should be chosen as array in
> this instance.    Perhaps we should make dot always choose the array as
> the output type??


I think that might be the simplest thing, dot overrides subtypes. BTW, here
is another ambiguity

In [6]: dot(array([[1]]),ones(2))
---------------------------------------------------------------------------
exceptions.ValueError                                Traceback (most recent
call last)

/home/charris/<ipython console>

ValueError: matrices are not aligned

Note that in this case dot acts like the rhs is always a column vector
although it returns a 1-d vector. I don't know that this is a bad thing, but
perhaps we should extend this behaviour to matrices, which would be
different from the now current 1-d is always a *row* vector, i.e.

In [8]: mat([[1]])*ones(2)
Out[8]: matrix([[ 1.,  1.]])

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20070326/bf0baa3b/attachment-0001.html 


More information about the Numpy-discussion mailing list