Dear all,<br><br> Can someone point me to a doc on dot product vectorisation ?<br><br>Here is what I try to do : <br><br>I've got a rotation function which looks like : <br><br>def rotat_scal(phi, V):<br> s = math.sin(phi)<br>
c = math.cos(phi)<br> M = np.zeros((3, 3))<br> M[2, 2] = M[1, 1] = c<br> M[1, 2] = -s<br> M[2, 1] = s<br> M[0, 0] = 1<br> return np.dot(M, V)<br><br>(where phi is a scalar, and V and array of size (3,1))<br>
<br>Now, I want to apply it to a time series of phi and V, in a vectorised way.<br>So, I tried to simply add a first dimension :<br>Phi is now of size(n) and V (n, 3).<br>(I really whish to have this shape, for direct correspondance to file).<br>
<br>The corresponding function looks like :<br><br>def rotat_vect(phi, V):<br> s = np.sin(phi)<br> c = np.cos(phi)<br> M = np.zeros((len(phi), 3, 3))<br> M[:, 2, 2] = M[:, 1, 1] = c<br> M[:, 1, 2] = -s<br> M[:, 2, 1] = s<br>
M[:, 0, 0] = np.ones (len(phi))<br> return np.dot(M, V)<br><br>It was not really a surprise to see that it didn't work :<br>> [...]<br>> return np.dot(M, V)<br>> ValueError: objects are not aligned<br>
<br>Any hint ?<br><br>Bruno.<br>