[Numpy-discussion] Howto vectorise a dot product ?

bruno Piguet bruno.piguet@gmail....
Tue Jun 9 13:56:29 CDT 2009


Dear all,

   Can someone point me to a doc on dot product vectorisation ?

Here is what I try to do :

I've got a rotation function which looks like :

def rotat_scal(phi, V):
    s = math.sin(phi)
    c = math.cos(phi)
    M = np.zeros((3, 3))
    M[2, 2] = M[1, 1] = c
    M[1, 2] = -s
    M[2, 1] = s
    M[0, 0] = 1
    return np.dot(M, V)

(where phi is a scalar, and V and array of size (3,1))

Now, I want to apply it to a time series of phi and V, in a vectorised way.
So, I tried to simply add a first dimension :
Phi is now of size(n) and V (n, 3).
(I really whish to have this shape, for direct correspondance to file).

The corresponding function looks like :

def rotat_vect(phi, V):
    s = np.sin(phi)
    c = np.cos(phi)
    M = np.zeros((len(phi), 3, 3))
    M[:, 2, 2] = M[:, 1, 1] = c
    M[:, 1, 2] = -s
    M[:, 2, 1] = s
    M[:, 0, 0] = np.ones (len(phi))
    return np.dot(M, V)

It was not really a surprise to see that it didn't work :
> [...]
>     return np.dot(M, V)
> ValueError: objects are not aligned

Any hint ?

Bruno.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090609/f5204772/attachment-0001.html 


More information about the Numpy-discussion mailing list