Python -Taking dot product of long list of arrays
<p>So I'm trying to to take the dot product of two arrays using numpy's dot product function.</p>

<pre><code>import numpy as np

MWFrPos_Hydro1 = subPos1[submaskFirst1]
x = MWFrPos_Hydro1
MWFrVel_Hydro1 = subVel1[submaskFirst1]
y = MWFrVel_Hydro1
MWFrPosMag_Hydro1 = [np.linalg.norm(i) for i in MWFrPos_Hydro1]

np.dot(x, y)
</code></pre>

<p>returns </p>

<pre><code>---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
&lt;ipython-input-135-9ef41eb4235d&gt; in &lt;module&gt;()
      6 
      7 
----&gt; 8 np.dot(x, y)

ValueError: shapes (1220,3) and (1220,3) not aligned: 3 (dim 1) != 1220 (dim 0)
</code></pre>

<p>And I using this function improperly?</p>

<p>The arrays look like this </p>

<pre><code>print x

[[  51.61872482  106.19775391   69.64765167]
 [  33.86419296   11.75729942   11.84990311]
 [  12.75009823   58.95491028   38.06708527]
 ..., 
 [  99.00266266   96.0210495    18.79844856]
 [  27.18083954   74.35041809   78.07577515]
 [  19.29788399   82.16114044    1.20453501]]

print y

[[  40.0402298  -162.62153625 -163.00158691]
 [-359.41983032 -115.39328766   14.8419466 ]
 [  95.92044067 -359.26425171  234.57330322]
 ..., 
 [ 130.17840576   -7.00977898   42.09699249]
 [  37.37852478  -52.66002655 -318.15155029]
 [ 126.1726532   121.3104248  -416.20855713]]
</code></pre>

<p>Would for looping <code>np.vdot</code> be more optimal in this circumstance?</p>

<p>You can't take the dot product of two <code>n * m</code> matrices unless <code>m == n</code> -- when multiplying two matrices, A and B, B needs to have as many columns as A has rows. (So you <em>can</em> multiply an <code>n * m</code> matrix with an <code>m * n</code> matrix.) </p>

<p>See <a href="http://mathinsight.org/matrix_vector_multiplication" rel="nofollow">this article on multiplying matrices</a>. </p>

python numpy