[Numpy-discussion] matrix indexing question

Zachary Pincus zpincus@stanford....
Fri Mar 30 00:31:49 CDT 2007


Looks promising!

> On 3/29/07, Bill Baxter <wbaxter@gmail.com> wrote: On 3/30/07,  
> Timothy Hochberg <tim.hochberg@ieee.org> wrote:
> > Note, however that you can't (for instance) multiply column  
> vector with
> > a row vector:
> >
> > >>> (c)(r)
> > Traceback (most recent call last):
> >   ...
> > TypeError: Cannot matrix multiply columns with anything
> >
>
> That should be allowed.  (N,1)*(1,M) is just an (N,M) matrix with
> entries C[i,j] = A[i,0]*B[0,]
>
> I thought about that a little, and while I agree that it could be  
> allowed, I'm not sure that it should be allowed. It's a trade off  
> between a bit of what I would guess is little used functionality  
> with some enhanced error checking (I would guess that usually  
> row*column signals a mistake). However, I don't care much one way  
> or the other; it's not hard to allow.

I'm also for allowing it; from the perspective of one writing code  
that "looks like" typical (if potentially technically incorrect)  
notation, being able to write direct analogs to a'b (to get a scalar)  
or ab' (to get an MxN matrix) and have everything "work" would be  
quite useful. Especially in various reconstruction tasks (e.g. using  
svd to approximate a given matrix with a lower-rank one), the "outer  
product" of a row and a column vector comes up often enough that I  
would be loathe to have it raise an error.

> I kind of like the idea of using call for multiply, though.  If it
> doesn't turn out to have any major down sides it could be a good way
> to give ndarray a concise syntax for "dot".
>
> We'll see how it goes down this time. I've proposed using call  
> before, since I've thought the matrix situation was kind of silly  
> for what seems like ages now, but it always sinks without a ripple.

The call syntax is nice, if a bit opaque to someone looking at the  
code for the first time. On the other hand, it's explicit in a way  
that overloaded multiplication just isn't. I like it (for what little  
that's worth).


Zach


>
>
> -- 
>
> //=][=\\
>
> tim.hochberg@ieee.org
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion



More information about the Numpy-discussion mailing list