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

Julien Hillairet julien.hillairet@gmail....
Wed Oct 17 03:11:36 CDT 2007

2007/10/16, Timothy Hochberg <tim.hochberg@ieee.org>:
>
>
> You might try tensordot. Without thinking it through too much:
> numpy.tensordot(a0, a1, axes=[-1,-1])
> seems to do what you want.
>
>
Thank you.

However, it works only for this simple example, where a0 and a1 are similar.
The tensor product increase the rank of the output, doesn't it ?
Although the dot product decrease the rank. Is there a ¨proper" solution if
a and b are general (3,N) vectors ?  By example :

In [16]: a = random.random_sample((3,5))
In [17]: b = random.random_sample((3,5))

what I'm searching for is :

In [18]: dotprod2(a,b)
Out[18]: array([ 0.28354876,  0.54474092,  0.22986942,  0.42822669,
0.98179793])

where I defined a "classical" (in the way I understand it. I may not
understand it properly ?) dot product between these 2 vectors.

def dotprod2(a,b):
return sum(a*b,axis=0)

or in maths notation : c_j = \sum_i a_{ij} b_{ij}