gpt4 book ai didi

python - 使用 Numba 在 Python 中求解最小二乘法

转载 作者:行者123 更新时间:2023-12-05 02:05:05 25 4
gpt4 key购买 nike

我在使用 Numba 求解 python 中的最小二乘法时遇到问题。这是我的代码:

import numpy as np
from numba import jit

@jit(nopython=True)
def test(A, B):
alpha = np.linalg.lstsq(A,B,rcond=None)
return alpha

A = np.random.rand(10,3)
B = np.random.rand(10,1)
alpha = test(A,B)

print(alpha)

没有“@jit(nopython=True)”这一行它就可以工作。使用“@jit”我有以下错误:

Invalid use of Function(<function lstsq at 0x000001767E21E318>) with argument(s) of type(s): (array(float64, 2d, C), array(float64, 2d, C), rcond=none)
* parameterized
In definition 0:
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of ExternalFunction(numba_ez_gelsd) with argument(s) of type(s): (Literal[int](100), int64, int64, int64, ArrayCTypes(dtype=float64, ndim=2), int64, ArrayCT
ypes(dtype=float64, ndim=2), int64, ArrayCTypes(dtype=float64, ndim=1), none, ArrayCTypes(dtype=int32, ndim=1))
Known signatures:
* (int8, int64, int64, int64, float64*, int64, float64*, int64, float64*, float64, int32*) -> int32
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: ExternalFunction(numba_ez_gelsd)
[2] During: typing of call at C:\Users\owner\anaconda3\lib\site-packages\numba\targets\linalg.py (1645)

有什么建议吗?

最佳答案

删除 rcond=None 关键字,它将正常工作。

关于python - 使用 Numba 在 Python 中求解最小二乘法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63836906/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com