[SciPy-User] array of matrices
Gustavo Goretkin
gustavo.goretkin at gmail.com
Fri Nov 25 17:14:14 EST 2011
I want to create an array, call it R, of matrices [M1,M2, M3, ...] . So R is 3D.
If v is a (column) vector, then np.dot(M1,v) matrix-multiples v by M1,
and produces another (column) vector. I want R to be shaped so that
np.dot(R,v) produces an array of column vectors [M1*v, M2*v, M3*v,
...]
Specifically, I want to define a function that resembles:
def rot_2d(theta):
return np.array([[np.cos(theta), -np.sin(theta)],
[np.sin(theta), np.cos(theta)]])
that works even if theta itself is an array.
np.dot(rot_2d(np.array([0,np.pi/2,np.pi]),np.array([1,0]) produces an
array like [ [1,0], [0,1], [-1,0] ].
Thanks!
Gustav
More information about the SciPy-User
mailing list