在Python中将scipy interp1d数组转换为浮点值

在Python中将scipy interp1d数组转换为浮点值,python,scipy,interpolation,Python,Scipy,Interpolation,在我当前的项目中,我目前有一个转换问题: 在第一步中,我使用scipy interp1d插入两个列表 f_speed = scipy.interpolate.interp1d(t, v, 'cubic') 之后,我想在这个函数中得到一个特定的点。该值现在是scipy中的一个数组,其中只有一个值 currentSpeed = f_speed(tpoint) # result: array(15.1944) 作为最后一步,我想用插值函数的值计算其他值,但我只得到0作为值。根本没有错误 rea

在我当前的项目中,我目前有一个转换问题: 在第一步中,我使用scipy interp1d插入两个列表

f_speed = scipy.interpolate.interp1d(t, v, 'cubic')
之后,我想在这个函数中得到一个特定的点。该值现在是scipy中的一个数组,其中只有一个值

 currentSpeed = f_speed(tpoint)
 # result: array(15.1944)
作为最后一步,我想用插值函数的值计算其他值,但我只得到0作为值。根本没有错误

real_distance = currentSpeed * (1/15)    # some calculations
# result: 0, all results with further calculations are zero
我需要从scipy数组转换为常规浮点值以继续计算。有什么功能可以做到这一点吗

我尝试了几种方法,比如V=currentSpeed[0],或者numpy的.tolist(在scipy中不可能)


提前谢谢你的帮助

您没有指定正在使用的Python版本,但是如果您使用的是Python 2.7,那么运算符
/
代表整数除法。这意味着
1/15
将产生0。无论您如何访问数组值,将某个值与该结果相乘将最终为0

要解决此问题,请确保至少有一个操作数是浮点数

result1 = 1/15 # Produces 0
result2 = 1.0/15 # Produces 0.06666666666666667
如果将此应用于代码,则应使用

real_distance = currentSpeed * (1.0/15)

您正在使用Python2吗?如果是这样,问题在于分工。 整数除法将产生整数,因此
1/15
将产生
0

试试
1.0/15
。通过使用
1.0
将其显式设置为浮点,则结果将与预期一致。

非常感谢您的快速回答。是的,我正在使用Python2.7,导入“来自未来导入部门”应该可以工作,希望我能试试!