Hi, I am doing optimization on a vector of rotation angles tx,ty and tz using scipy.optimize.fmin. Unfortunately the function that I am optimizing needs the rotation matrix corresponding to this vector so it is getting constructed once for each iteration with new values. >From profiling I can Hi,
I am doing optimization on a vector of rotation angles tx,ty and tz using scipy.optimize.fmin. Unfortunately the function that I am optimizing needs the rotation matrix corresponding to this vector so it is getting constructed once for each iteration with new values. >From profiling I can see that the function I am using to construct this rotation matrix is a bottleneck. I am currently using: def rotation(theta): tx,ty,tz = theta Rx = np.array([[1,0,0], [0, cos(tx), -sin(tx)], [0, sin(tx), cos(tx)]]) Ry = np.array([[cos(ty), 0, -sin(ty)], [0, 1, 0], [sin(ty), 0, cos(ty)]]) Rz = np.array([[cos(tz), -sin(tz), 0], [sin(tz), cos(tz), 0], [0,0,1]]) return np.dot(Rx, np.dot(Ry, Rz)) Is there a faster way to do this? Perhaps I can do this faster with a small cython module, but this might be overkill? Thanks for any help, Jonathan.see that the function I am using to construct this rotation matrix is a bottleneck. I am currently using: def rotation(theta): tx,ty,tz = theta Rx = np.array([[1,0,0], [0, cos(tx), -sin(tx)], [0, sin(tx), cos(tx)]]) Ry = np.array([[cos(ty), 0, -sin(ty)], [0, 1, 0], [sin(ty), 0, cos(ty)]]) Rz = np.array([[cos(tz), -sin(tz), 0], [sin(tz), cos(tz), 0], [0,0,1]]) return np.dot(Rx, np.dot(Ry, Rz)) Is there a faster way to do this? Perhaps I can do this faster with a small cython module, but this might be overkill? Thanks for any help, Jonathan. _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion