Python 麻巴元';不接受numpy数组数据类型

Python 麻巴元';不接受numpy数组数据类型,python,pandas,numba,Python,Pandas,Numba,我有以下数据帧: time t sp 598258 2017-01-02 00:00:00 -2.634766 89892.492188 598259 2017-01-02 01:00:00 -2.753906 89921.398438 598260 2017-01-02 02:00:00 -2.730469 89896.914062 598261 2017-01-02 03:00:00 -2.765625

我有以下数据帧:

                      time         t            sp
598258 2017-01-02 00:00:00 -2.634766  89892.492188
598259 2017-01-02 01:00:00 -2.753906  89921.398438
598260 2017-01-02 02:00:00 -2.730469  89896.914062
598261 2017-01-02 03:00:00 -2.765625  89874.468750
598262 2017-01-02 04:00:00 -2.855469  89864.609375
598263 2017-01-02 05:00:00 -3.005859  89846.929688
598264 2017-01-02 06:00:00 -3.011719  89877.875000
598265 2017-01-02 07:00:00 -2.900391  89873.109375
598266 2017-01-02 08:00:00 -2.416016  89891.812500
598267 2017-01-02 09:00:00 -2.126953  89882.289062
和以下代码:

import pandas as pd
import numpy as np
from numba import jit
@jit(nopython=True)
def en(t,p):
    dd = np.empty((t.size),np.float16)
    for i in range(len(t)):
        dd[i]=p[i]/287.05/(t[i]+273.15)
    return dd

ex=en(dfx['t'].values,dfx['sp'].values)
我得到一个错误:

TypingError: non-precise type pyobject
[1] During: typing of argument at dd = np.empty((t.size),np.float16)

我知道我必须为numba定义精确的类型才能接受它,我想我只是用
np.float16
这样做的,但错误是存在的。非常感谢您为解决此问题提供的任何帮助

您必须根据所需的精度更改为浮点64或32:

from numba import jit
@jit(nopython=True)
def en(t,p):
    dd = np.empty((t.size),np.float64)
    for i in range(len(t)):
        dd[i]=p[i]/287.05/(t[i]+273.15)
    return dd

ex=en(dfx['t'].values,dfx['sp'].values)
输出:

array([1.15764165, 1.15852414, 1.15810831, 1.1579697 , 1.15822752,
       1.15864432, 1.15906853, 1.15852962, 1.15669754, 1.15534144])

那会解决的

@Ethan试过了,还是一样的错误。不幸的是,这在我的机器上不起作用。我也有同样的错误。我试图用
dd=np.empty((dfx['t'].values.size),np.float64)直接传递
,我得到错误
TypingError:无法确定
@user2727167的类型,很有趣。float16在我的机器上肯定不起作用,它给出的错误与你得到的相同,但其他两个起作用。您运行的软件包的版本是什么,可能您有一个旧版本,只需要进行pip升级。我只是想跳出框框思考一下,因为较高的浮标对我有用。我有numpy'1.16.2',pandas 0.25.3和numba'0.46.0',我发现了问题所在。
dfx['t']
中的值列表在原始数据帧中定义为
float16
,甚至有一些NAN。当过滤这些数据时,一切正常。非常感谢。