[Numpy-discussion] Howto vectorise a dot product ?
Charles R Harris
charlesr.harris at gmail.com
Tue Jun 9 16:46:25 EDT 2009
On Tue, Jun 9, 2009 at 12:56 PM, bruno Piguet <bruno.piguet at gmail.com>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.
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20090609/257f78d1/attachment.html>
More information about the NumPy-Discussion
mailing list