[Numpy-discussion] working on multiple matrices of the same shape
Mon Nov 24 10:27:03 CST 2008
>> 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]])
Are you sure ? Here it reports
ValueError: setting an array element with a sequence.
probably because theta, sintheta and costheta are 1-d arrays of n>1 elements.
However, I'll drop them and use list of matrices as Charles suggested.
Thanks to both if you.
More information about the Numpy-discussion