Python 将numpy数组转换为整数数组
我有一个数组Python 将numpy数组转换为整数数组,python,arrays,numpy,Python,Arrays,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:只有size-1数组可以转换为Python标量如果您已经在使用numpy import numpy as np lengt
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:只有size-1数组可以转换为Python标量如果您已经在使用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)
输出:
P2x=int(…)
您正在将其强制转换为int,这是一个scalarI想要的整数值请使用new\u array=your\u array.astype(np.int)
请明确定义您想要的内容。您想要整数的numpy数组、整数的array.array或整数的列表吗?int
(和math.cos()
)一次只能处理一个数字,而不是一个数字数组。
[128 178 245 212]