首页 > 解决方案 > numba.core.errors.TypingError:使用 np.random.randint() 时

问题描述

如何np.random.randint与 numba 一起使用,因为这会引发非常大的错误,https://hastebin.com/kodixazewo.sql

from numba import jit
import numpy as np
@jit(nopython=True)
def foo():
    a = np.random.randint(16, size=(3,3))
    return a
foo()

标签: pythonnumpynumba

解决方案


有关var的更多详细信息,请参见此处。nopython

from numba import jit
import numpy as np
import warnings

warnings.filterwarnings("ignore")  # suppress NumbaWarning - remove and read for more info
@jit(nopython=False)   # I guess we need the Python interpreter to randomize with more than 2 parameters in np.random.randint()        
def foo():
    a = np.random.randint(16, size=(3,3))
    return a
foo()

推荐阅读