为了账号安全,请及时绑定邮箱和手机立即绑定

将 numpy 数组转换为整数数组

将 numpy 数组转换为整数数组

qq_遁去的一_1 2023-12-12 21:14:07
我有数组length = 7angle = 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
查看完整描述

1 回答

?
偶然的你

TA贡献1841条经验 获得超3个赞

math如果您已经在使用,则不需要该模块numpy


import numpy as np


length = 7

angle = 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]


查看完整回答
反对 回复 2023-12-12
  • 1 回答
  • 0 关注
  • 32 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信