如何解决使用Numba在Python中求解最小二乘
我在使用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,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,ArrayCTypes(dtype=float64,ndim=2),ArrayCT
ypes(dtype=float64,ndim=1),none,ArrayCTypes(dtype=int32,ndim=1))
Known signatures:
* (int8,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 关键字,它将正常工作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。