[Numpy-discussion] Howto vectorise a dot product ?
Charles R Harris
Tue Jun 9 15:46:25 CDT 2009
On Tue, Jun 9, 2009 at 12:56 PM, bruno Piguet <firstname.lastname@example.org>wrote:
> 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).
Well, in this case you can use complex multiplication and either work with
just the x,y components or use two complex components, i.e., [x + 1j*y, z].
In the first case you can then do the rotation as V*exp(1j*phi). If you want
more general rotations, a ufunc for quaternions would do the trick.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion