Я реализую программу, которая делает случайную выборку в Python 3.6.7, и есть одна функция, которую я просто не могу скомпилировать с Numba. Самая последняя версия:
import numpy as np
from numba import jit
@jit(nopython=True)
def bs_stat_numba(data, iter_n=1000):
iter_mean = np.mean(np.random.choice(data, size =(len(data),iter_n)))
iter_std = np.std(np.random.choice(data, size =(len(data),iter_n)))
bs_mean = np.float32(np.mean(iter_mean))
bs_std = np.float32(np.mean(iter_std))
return bs_mean, bs_std
data = [[1,2,3,4], [12,23,45,67], [10,11,12,23,45,6]]
zkzq_dict = []
for i in tqdm(range(len(data))):
bs_mean, bs_std = bs_stat_numba(data[i])
zqPre_upper = bs_mean + 2*bs_std
zqPre_lower = bs_mean - 2*bs_std
zkzq_dict.append([zqPre_lower, zqPre_upper])
Here is the error as follows:
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<function mean at 0x7f8b7c103730>) with argument(s) of type(s): (float32)
* parameterized
In definition 0:
All templates rejected with literals.
In definition 1:
All templates rejected without literals.
This error is usually caused by passing an argument of a type that is unsupported by the named function.
[1] During: resolving callee type: Function(<function mean at 0x7f8b7c103730>)
[2] During: typing of call at <ipython-input-244-488a401000dd> (8)
File "<ipython-input-244-488a401000dd>", line 8:
def bs_stat_numba(data, iter_n=1000):
<source elided>
bs_mean = np.float32(np.mean(iter_mean))
Я использую следующие версии: numba == 0.45.1, numpy == 1.17.2. Большое спасибо.