BPC=[BRad.*cos(BC)' BRad.*sin(BC)' zeros(1,6)']
这是我转换为Python的MATLAB代码:
BPC=np.transpose(np.array([BRad * np.cos(BC),BRad * np.sin(BC),np.zeros((1,6))]))
MATLAB给出了一个(6,3)矩阵,Python给出了一个(3,)矩阵。是什么导致的?
看起来你得到的是三个元素的向量,前两个是具有六个元素的向量,最后一个是具有1x6元素的矩阵。 Numpy不能将这些“扁平”成单个矩阵。
>>> BRad = 1
>>> BC = np.array([1,2,3,4,5,6])
>>> np.transpose(np.array([BRad * np.cos(BC), BRad * np.sin(BC), np.zeros((1,6))]))
array([ array([ 0.54030231, -0.41614684, -0.9899925 , -0.65364362, 0.28366219,
0.96017029]),
array([ 0.84147098, 0.90929743, 0.14112001, -0.7568025 , -0.95892427,
-0.2794155 ]),
array([[ 0., 0., 0., 0., 0., 0.]])], dtype=object)
而不是np.zeros((1,6))
,尝试只是np.zeros(6)
>>> np.transpose(np.array([BRad * np.cos(BC), BRad * np.sin(BC), np.zeros(6)]))
array([[ 0.54030231, 0.84147098, 0. ],
[-0.41614684, 0.90929743, 0. ],
[-0.9899925 , 0.14112001, 0. ],
[-0.65364362, -0.7568025 , 0. ],
[ 0.28366219, -0.95892427, 0. ],
[ 0.96017029, -0.2794155 , 0. ]])