[Numpy-discussion] A basic question on the dot function

Timothy Hochberg tim.hochberg@ieee....
Tue Oct 16 15:08:30 CDT 2007


On 10/16/07, Julien Hillairet <julien.hillairet@gmail.com> wrote:
>
> 2007/10/16, Bill Baxter <wbaxter@gmail.com>:
> >
> > dot() also serves as Numpy's matrix multiply function.  So it's trying
> > to interpret that as a (3,N) matrix times a (3,N) matrix.
> >
> > See examples here:
> >
> > http://www.scipy.org/Numpy_Example_List_With_Doc#head-2a810f7dccd3f7c700d1076f15078ad1fe3c6d0d
> >
> > --bb
> >
>
> 2007/10/16, Charles R Harris < charlesr.harris@gmail.com>:
> >
> >
> >
> > Dot is matrix multiplication, not the "dot" product you were expecting.
> > It is also a bit ambiguous, as you see with the 1-D vectors, where you got
> > what you expected.
> >
> > Chuck
> >
>
>
> 2007/10/16, Robert Kern <robert.kern@gmail.com>:
> >
> > When given two 2-D arrays, dot() essentially does matrix multiplication.
> > The
> > last dimension of the first argument is matched with the next-to-last
> > dimension
> > of the second argument.
> >
> > --
> > Robert Kern
>
>
> Thank you for your answers. So, is there a "proper" solution to do the dot
> product as I had expected it ?
>

You might try tensordot. Without thinking it through too much:
numpy.tensordot(a0, a1, axes=[-1,-1])
seems to do what you want.



-- 
.  __
.   |-\
.
.  tim.hochberg@ieee.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20071016/57572164/attachment.html 


More information about the Numpy-discussion mailing list