[Numpy-discussion] working on multiple matrices of the same shape

Stéfan van der Walt stefan at sun.ac.za
Mon Nov 24 05:52:53 EST 2008


2008/11/21 Sébastien Barthélemy <barthelemy at crans.org>:
> In this spirit, in numpy a set of rotation matrices could be built in
> the following way:
>
> def rotx(theta):
>    """
>    SE(3) matrices corresponding to a rotation around x-axis. Theta is
> a 1-d array
>    """
>    costheta = np.cos(theta)
>    sintheta = np.sin(theta)
>    H = np.zeros((theta.size,4,4))
>    H[:,0,0] = 1
>    H[:,3,3] = 1
>    H[:,1,1] = costheta
>    H[:,2,2] = costheta
>    H[:,2,1] = sintheta
>    H[:,1,2] = sintheta
>    return H

Btw, you can just create an array of these elements directly:

np.array([[costheta, -sintheta, 0],
          [sintheta, costheta , 0],
          [0       , 0        , 1]])

Regards
Stéfan



More information about the NumPy-Discussion mailing list