Showing ValueError: shapes (1,3) and (1,3) not aligned: 3 (dim 1) != 1 (dim 0)
<p>I am trying to run this code,and the last 2 dot products are showing error as suggested in the heading. I checked the size of the matrices and both are (3, 1), then why it is showing me an error while doing dot product?</p>

<pre><code>coordinate1 = [-7.173, -2.314, 2.811] 
coordinate2 = [-5.204, -3.598, 3.323] 
coordinate3 = [-3.922, -3.881, 4.044] 
coordinate4 = [-2.734, -3.794, 3.085] 

import numpy as np 
from numpy import matrix
coordinate1i=matrix(coordinate1)
coordinate2i=matrix(coordinate2)
coordinate3i=matrix(coordinate3)
coordinate4i=matrix(coordinate4)

b0 = coordinate1i - coordinate2i
b1 = coordinate3i - coordinate2i
b2 = coordinate4i - coordinate3i

n1 = np.cross(b0, b1)
n2 = np.cross(b2, b1)

n12cross = np.cross(n1,n2)
x1= np.cross(n1,b1)/np.linalg.norm(b1)
print np.shape(x1)
print np.shape(n2)
np.asarray(x1)
np.asarray(n2)

y = np.dot(x1,n2)
x = np.dot(n1,n2)

return np.degrees(np.arctan2(y, x))
</code></pre>

<p>Unlike standard arithmetic, which desires matching dimensions, dot products require that the dimensions are one of:</p>

<ul>
<li><code>(X..., A, B) dot (Y..., B, C) -&gt; (X..., Y..., A, C)</code>, where <code>...</code> means "0 or more different values</li>
<li><code>(B,) dot (B, C) -&gt; (C,)</code></li>
<li><code>(A, B) dot (B,) -&gt; (A,)</code></li>
<li><code>(B,) dot (B,) -&gt; ()</code></li>
</ul>

<p>Your problem is that you are using <code>np.matrix</code>, which is totally unnecessary in your code - the main purpose of <code>np.matrix</code> is to translate <code>a * b</code> into <code>np.dot(a, b)</code>. As a general rule, <code>np.matrix</code> is probably not a good choice.</p>

python arrays numpy