[Numpy-discussion] A basic question on the dot function
Charles R Harris
Tue Oct 16 13:23:36 CDT 2007
On 10/16/07, Julien Hillairet <firstname.lastname@example.org> wrote:
> First of all, I'm sorry if this question had already been asked. I've
> searched on the gmane archive and elsewhere on internet, but I didn't found
> the answer to my question.
> As expected, the dot product of 2 'classical' vectors works fine :
> In : a0 = numpy.array([1,2,3])
> In : numpy.dot(a0,a0)
> Out: 14
> What I don't understand, is why the dot product of a (3,N) vector gives an
> error :
> In : a1 = numpy.array([[1,2,3],[1,2,3],[1,2,3],[1,2,3]])
> In : numpy.dot(a1,a1)
> <type 'exceptions.ValueError'> Traceback (most recent call
> <type 'exceptions.ValueError'>: objects are not aligned
> instead of what I've expected ; an array([14 14 14 14]).
> Of course, I've found an alternative in doing :
> In : numpy.sum(a1*a1,axis=1)
> Out: array([14, 14, 14, 14])
> But I like to understand my mistakes or misunderstands :) So, could
> someone explained me what I've missed ? Thanks in advance.
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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion