如何在 numba 中使用 zscore

How to use zscore with numba

我正在尝试制作一个互相关矩阵和一个 2800x2800 的移位矩阵,但我想对值进行归一化。为此,我正在使用 zscore,但 numba 无法识别它。我必须找到一些东西,因为如果没有 numba,我无法像那样进行双循环。我的代码看起来像这样:

@njit

def crossCor(timeSeries):
for i in range(timeSeries.shape[0]):
    print(i)
    for j in range(timeSeries.shape[0]):
        cor = (np.correlate(zscore(timeSeries, axis = 1)[i, :], zscore(timeSeries, axis = 1)[j, :], mode = 'full')) / timeSeries.shape[1]
        crossCorrelation[i, j] = max(cor[timeSeries.shape[1] - 11:timeSeries.shape[1] - 1])
        crossCorrelation[j, i] = max(cor[timeSeries.shape[1] - 1:timeSeries.shape[1] + 9])
        decalage[i, j] = timeSeries.shape[1] - 1 - np.where(cor == max(cor[timeSeries.shape[1] - 11:timeSeries.shape[1] -1]))[0][0]
        decalage[i, j] = np.where(cor == max(cor[timeSeries.shape[1] - 1:timeSeries.shape[1] + 9]))[0][0] - timeSeries.shape[1] - 1

@njit 是 def 之前的一行,但是如果我尝试将它放在代码部分,堆栈不会使我的代码看起来很好。

我假设你指的是 zscore function from Scipy,因为你没有指定。

根据 Numba reference manual,Numba 仅支持特定的一组 Python 功能和开箱即用的 Numpy 功能。因此,您可以找到使此功能与 Numba 一起使用的方法,或者找到 zscore 的 Numba 兼容实现,或者尝试在 Numba 的约束下实现您自己的实现。

通过快速搜索,我还找到了一个旨在“让 Numba 知道 Scipy” 的项目,但似乎缺少它的文档:https://github.com/numba/numba-scipy

编辑:另一种选择是仅使用 zscore outside/before 使用您正在应用 numba.jit 的函数,从而完全避免该问题。

编辑 2:进一步参考 Numba 支持的功能