Python 矩阵类型

coordinate_1 = np.array([[(np.cos(0) * np.cos(alpha_radian),

                       np.cos(0) * np.sin(alpha_radian) * np.sin(

                           alpha_radian) - np.sin(0) * np.cos(alpha_radian),

                       np.cos(0) * np.sin(alpha_radian) * np.cos(alpha_radian))],

                     [np.sin(0) * np.cos(alpha_radian),

                      (np.sin(0) * np.sin(alpha_radian) * np.sin(

                          alpha_radian)) - (

                              np.cos(0) * np.cos(alpha_radian)),

                      (np.sin(0) * np.sin(alpha_radian) * np.cos(

                          alpha_radian)) - (

                              np.cos(0) * np.sin(alpha_radian))],

                     [-np.sin(alpha_radian),

                      np.cos(alpha_radian) * np.sin(alpha_radian),

                      np.cos(alpha_radian) * np.cos(alpha_radian)]])

print(coordinate_1)

print(type(coordinate_1))

并输出


[list([(0.7071067811865476, 0.4999999999999999, 0.5)])

list([0.0, -0.7071067811865476, -0.7071067811865475])

list([-0.7071067811865475, 0.5, 0.5000000000000001])]

<class 'numpy.ndarray'>

为什么矩阵输出总是在开始矩阵处包含一个“列表” ,如何将它们转换为浮点数,我可以进行一个简单的矩阵乘法。


jeck猫
浏览 94回答 1
1回答

小唯快跑啊

我不确定为什么这些是列表,但我认为你更大的问题是你试图强加看起来像 3d 旋转的元素,对吗?如果是这样,请不要使用当前的实现,而是使用 scipy.spatial.transform.Rotation`。那里的例子:from&nbsp;scipy.spatial.transform&nbsp;import&nbsp;Rotation&nbsp;as&nbsp;R r&nbsp;=&nbsp;R.from_euler('xyz',&nbsp;angles=[-45,&nbsp;45,&nbsp;0],&nbsp;degrees=True) r.as_matrix()这输出:array([[&nbsp;7.07106781e-01,&nbsp;-5.00000000e-01,&nbsp;&nbsp;5.00000000e-01], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[-5.55111512e-17,&nbsp;&nbsp;7.07106781e-01,&nbsp;&nbsp;7.07106781e-01], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[-7.07106781e-01,&nbsp;-5.00000000e-01,&nbsp;&nbsp;5.00000000e-01]])这和你的很相似。只需根据您使用的 alpha_radians 来调整角度即可。这比写那些令人头痛的行要好得多:)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python