如何使用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()
uj5u.com熱心網友回復:
參見這里以了解更多關于nopythonvar的細節。
from numba import jit
import numpy as np
import warnings
warnings.filterwarnings("ignore") # 抑制NumbaWarning - 洗掉并閱讀更多資訊。
@jit(nopython=False) # 我想我們需要Python解釋器在np.random.randint()中用2個以上的引數進行隨機化。
def foo()。
a = np.random.randint(16, size=(3,3))
return a
foo()
uj5u.com熱心網友回復:
你可以使用np.ndindex來回圈你想要的輸出大小,并為每個元素單獨呼叫np.random.randint。
確保輸出的資料型別足以支持來自randint呼叫的整數范圍。
fromnumba importnjit
import numpy as np
@njit
def foo(size=(3。 3))。)
out = np.empty(size, dtype=np.uint16)
for idx in np.ndindex(size):
out[idx] = np.random.randint(16)
return out
這使得它可以適用于任何任意的形狀:
。foo(size=(2,2, 2)
結果是:
array([[8, 7]。
[15, 2]]。
[[ 4, 13]。
[5, 11]], dtype=uint16)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/326856.html
標籤:
上一篇:如何列出PowerShell中定義的所有多載cmdlet?
下一篇:我如何解決這個錯誤?TypeError:_append_dispatcher()缺少1個必要的位置引數:'values'。
