[英]Subtracting two lists but the values are not adding up in Python
I want to perform the operation: roll_all-theta_all
.我要执行操作:
roll_all-theta_all
。 Both of them are lists
containing two values each and the result is supposed to be listed in the column named 'roll' on my panda.DataFrame
.它们都是包含两个值的
lists
,结果应该列在我的panda.DataFrame
上名为“roll”的列中。 However when I do so, the 2nd row value of column 'roll' does not add up.但是,当我这样做时,'roll' 列的第二行值不会相加。 Although it cannot be seen because I perform
theta_all
operation in other parts of my code, I obtain the values the same way I obtain the values of roll_all
, ie, by creating an empty list
and then append the values to it.尽管由于我在代码的其他部分执行
theta_all
操作而看不到它,但我获取值的方式与获取roll_all
的值相同,即通过创建一个空list
然后 append 将值分配给它。 Here is my code:这是我的代码:
pyr = pd.DataFrame(columns = ['pitch','yaw','roll'])
for para in GTparas:
Mr = np.array([[np.cos(para[2]), -np.sin(para[2]), 0],[np.sin(para[2]), np.cos(para[2]), 0],[0, 0, 1]])
My = np.array([[np.cos(para[1]), 0, np.sin(para[1])],[0, 1, 0],[-np.sin(para[1]), 0, np.cos(para[1])]])
Mp = np.array([[1, 0, 0],[0, np.cos(para[0]), -np.sin(para[0])],[0, np.sin(para[0]), np.cos(para[0])]])
M1 = np.dot(Mr,My)
M = np.dot(M1,Mp)
pitch = np.arctan(M[2,1]/M[2,2])
yaw = np.arctan(M[2,0]/((((M[0,0])**2)+((M[1,0])**2))**(1/2)))
roll = np.arctan(M[1,0]/M[0,0])
roll_all = []
roll_all.append(roll)
print(roll_all)
c = [a - b for a, b in zip(roll_all, theta_all)]
#c = np.array(roll_all) - np.array(theta_all)
pyr = pyr.append({'pitch':pitch,'yaw':yaw,'roll':c},ignore_index = True) # from Z-Y-X to X-Y-Z
print(pyr)
I am also attaching the values in my lists for theta_all
and the second image shows the values in roll_all
and what I get when I print pyr
.我还在我的列表中附加了
theta_all
的值,第二张图片显示了roll_all
中的值以及我打印pyr
时得到的值。
Summarizing:总结:
pyr = pd.DataFrame(columns = ['pitch','yaw','roll'])
for para,theta in zip(GTparas, theta_all):
Mr = np.array([[np.cos(para[2]), -np.sin(para[2]), 0],[np.sin(para[2]), np.cos(para[2]), 0],[0, 0, 1]])
My = np.array([[np.cos(para[1]), 0, np.sin(para[1])],[0, 1, 0],[-np.sin(para[1]), 0, np.cos(para[1])]])
Mp = np.array([[1, 0, 0],[0, np.cos(para[0]), -np.sin(para[0])],[0, np.sin(para[0]), np.cos(para[0])]])
M1 = np.dot(Mr,My)
M = np.dot(M1,Mp)
pitch = np.arctan(M[2,1]/M[2,2])
yaw = np.arctan(M[2,0]/((((M[0,0])**2)+((M[1,0])**2))**(1/2)))
roll = np.arctan(M[1,0]/M[0,0]) - theta
pyr = pyr.append({'pitch':pitch,'yaw':yaw,'roll':roll},ignore_index = True)
print(pyr)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.