【问题标题】:np.zeros in numba? How to make itnumba 中的 np.zeros?如何制作
【发布时间】:2021-07-31 04:21:27
【问题描述】:

您好,我有一个关于使用 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], state_matrix.shape[1]], dtype=np.uint8)
    ^

任何想法如何使它工作?任何 numba 类型的函数之类的?

【问题讨论】:

    标签: python numpy jit numba


    【解决方案1】:

    我认为将形状作为元组而不是列表传递可以解决问题。像这样:

    new_state_matrix = np.zeros((state_matrix.shape[0], state_matrix.shape[1]), dtype=np.uint8)
    

    【讨论】:

    • 是的,这解决了问题。更简单:np.zeros(state_matrix.shape[:2], dtype=np.uint8)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-29
    • 2019-01-01
    • 2019-02-15
    • 1970-01-01
    • 1970-01-01
    • 2018-07-26
    • 2015-09-08
    相关资源
    最近更新 更多