python - 将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
解决方案
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]
推荐阅读
- python - 根据另一列中的字符串内容在 pandas 中创建类别列
- post - “此路线不支持 POST 方法。支持的方法:GET、HEAD
- swift - “navigationController?.pushViewController”和“performSegue”之间有什么区别吗
- php - Laravel 5.5 中 m:m 雄辩关系的 1:1 变体:示例有效吗?
- django - Django-Rest-Framework 无法解析超链接关系的 URL
- java - 我应该如何将我的 Java 代码转换为 J-meter BeanShell PreProcessor
- javascript - `Hooks` 是否可以用来替代 React 中的 `Redux`?
- regex - 使用正则表达式 python3 找到固定日期格式?
- swift - Swift 5 中切换案例“@unknown default”和“default”之间的区别
- php - 插入时出现Mysqlierror