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

Julien Hillairet julien.hillairet@gmail....
Tue Oct 16 13:14:35 CDT 2007


Hello,


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 [50]: a0 = numpy.array([1,2,3])
In [51]: numpy.dot(a0,a0)
Out[51]: 14

What I don't understand, is why the dot product of a (3,N) vector gives an
error :

In [52]: a1 = numpy.array([[1,2,3],[1,2,3],[1,2,3],[1,2,3]])
In [54]: numpy.dot(a1,a1)
<type 'exceptions.ValueError'>            Traceback (most recent call last)
<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 [61]: numpy.sum(a1*a1,axis=1)
Out[61]: 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.

Best regards,

JH
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20071016/2bd8310f/attachment.html 


More information about the Numpy-discussion mailing list