将 numpy 数组转换为整数数组

我有数组


length = 7

angle = 30  

x = [1.21660254e+02, 1.71660254e+02, 2.38660254e+02, 2.05660254e+02]

我试过这个


P2x =  int(np.round(x + length * math.cos(math.radians(-angle))))

给我错误TypeError: only size-1 arrays can be converted to Python scalars


qq_遁去的一_1
浏览 38回答 1
1回答

偶然的你

math如果您已经在使用,则不需要该模块numpyimport numpy as nplength = 7angle = 30 x = [1.21660254e+02, 1.71660254e+02, 2.38660254e+02, 2.05660254e+02]xP2x = np.round(np.array(x) + length * np.cos(np.radians(-angle))).astype(int)print(xP2x)出去:[128 178 245 212]
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python