如何解决numba 中的 np.zeros?如何制作
嗨,我有一个关于使用 jit 编译器制作零填充数组的问题。主要是我想制作这样的数组:
new_state_matrix = np.zeros([state_matrix.shape[0],state_matrix.shape[1]],dtype=np.uint8)
我有这个错误:
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<built-in function zeros>) found for signature:
>>> zeros(list(int64)<iv=None>,dtype=class(uint8))
There are 2 candidate implementations:
- Of which 2 did not match due to:
Overload of function 'zeros': File: numba\core\typing\npydecl.py: Line 511.
With argument(s): '(list(int64)<iv=None>,dtype=class(uint8))':
No match.
During: resolving callee type: Function(<built-in function zeros>)
During: typing of call at C:\Users\d4wt0\Desktop\koderka\MW\proj1\venv\methods.py (850)
File "methods.py",line 850:
def nbh_check(state_matrix,img_matrix,nbh):
new_state_matrix = np.zeros([state_matrix.shape[0],dtype=np.uint8)
^
任何想法如何使它工作?任何 numba 类型的函数或其他东西?
解决方法
我认为将形状作为元组而不是列表传递可以解决问题。像这样:
new_state_matrix = np.zeros((state_matrix.shape[0],state_matrix.shape[1]),dtype=np.uint8)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。