I have following dataframe:
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
and following code:
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)
I get error:
TypingError: non-precise type pyobject
[1] During: typing of argument at dd = np.empty((t.size),np.float16)
I know I must define precise type for numba to accept it, i think I did just that with np.float16
but error is present. Any help to resolve this is appreciated
You have to change to float 64 or 32 depending on the precision you want:
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)
output:
array([1.15764165, 1.15852414, 1.15810831, 1.1579697 , 1.15822752,
1.15864432, 1.15906853, 1.15852962, 1.15669754, 1.15534144])
That will fix it!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With