Python Rotation Matrix Error -


i getting not aligned shapes error in python , not sure how resolve it. goal take dot product between array , rotation matrix.

i calling 2 text file lists , converting them arrays. not converting 2 lists arrays , matrix form correctly?

x=dataset[:,0]  y=dataset[:,1]  z_nodatum=dataset[:,2] stage=dataset[:,17] amp=dataset[:,5]  x=np.array(x) y=np.array(y)  z=-(z_nodatum-2919)  z=np.array(z)   = np.column_stack(([x],[y]))   theta = np.radians(20) c,s =np.cos(theta), np.sin(theta) r = np.matrix('{} {};{} {}' .format(c, -s, s, c))  b=a*r 

also take b , convert x , y list plotting.

thanks help.

i'm guessing dataset array 2d array, , not that, it numpy array since can't index normal python arrays via [:(tuple)]

given that, appears these 5 lines

x=dataset[:,0]  y=dataset[:,1]  z_nodatum=dataset[:,2] stage=dataset[:,17] amp=dataset[:,5] 

actually correspond specified columns in dataset. x, y, z_notatum, stage, , amp 1xn arrays.

given this, lines:

x=np.array(x) y=np.array(y) 

do nothing, x , y numpy arrays. z=-(z_nodatum-2919) subtracts 2919 every element, negates result , returns resulting numpy array, if wanted. again, z=np.array(z) doesn't anything, had numpy array in first place.

this next line don't think want do.

a = np.column_stack(([x],[y])) 

what takes array of 1xn arrays x , y, , column stacks them, ends being [[x1, x2... xn, y1, y2...yn]]. wanted was:

a = np.column_stack((x,y)) 

which returns 2d numpy array of columns x , y [[x1,y1],[x2, y2]...[xn,yn]]. note if going x , y have done in beginning:

a = dataset[:,:2] 

this have given x , y in first place if right next each other in dataset (takes 0 -> n-1 columns, n here 2)

your rotation matrix appears valid, note, should have created via:

theta = np.radians(20) cos_theta,sine_theta =np.cos(theta), np.sin(theta) r = np.matrix([[cos_theta, -sine_theta], [sine_theta, cos_theta]]) 

you use string format version when more convenient (ie reading text elsewhere) or have complicated structure necessitates it. not case here.

b=a*r 

in version have 1x1xn np array a, , 2x2 r. isn't going work.

with revised changes suggest, row x column, nx2 * 2x2 operation, valid since inner sizes match. rotated x , y out of b, can doing in beginning, b nx2 numpy array @ point (a*b = c, size of c a.rows x b.cols, outer size values):

x_rotated = b[:,0] y_rotated = b[:,1] 

now should work. careful matrix multiplication in numpy though, make sure @ least 1 of values matrix, otherwise doing element wise multiplication (your r matrix). additionally order of operations may make 2 arrays in equation (ie array * array * matrix) perform element wise multiplication before matrix operation.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -