Rob*_*Ren 0 jit numpy python-3.x numba numpy-ndarray
收到此错误消息:
Failed at nopython (nopython frontend)
[1m[1m[1mInvalid usage of Function(<function argsort at 0x0000000002A67840>) with parameters (array(float64, 2d, C), axis=int64)
* parameterized
In definition 0:
Run Code Online (Sandbox Code Playgroud)
使用此代码时
def rankbids(bids, shifts, groupPeriod, period):
rowsSize = bids.shape[0];
finaltable = np.zeros((rowsSize, groupPeriod), dtype=np.float64)
for i in range(0, period):
#for 0 to 99
#CONSTANT 4 UPDATE WHEN NEEDED
for worker in range(rowsSize):
shiftNum = int(shifts[worker,i]);
finaltable[worker, (shiftNum+i*10)] = bids[worker,i];
if shiftNum == 1:
finaltable[worker, (shiftNum+i*10)] = bids[worker,i];
finaltable[worker, (shiftNum+1+i*10)] = bids[worker,i];
finaltable[worker, (shiftNum+2+i*10)] = bids[worker,i];
elif shiftNum == 2:
finaltable[worker, (shiftNum+2+i*10)] = bids[worker,i];
finaltable[worker, (shiftNum+3+i*10)] = bids[worker,i];
finaltable[worker, (shiftNum+4+i*10)] = bids[worker,i];
elif shiftNum == 3:
finaltable[worker, (shiftNum+4+i*10)] = bids[worker,i];
finaltable[worker, (shiftNum+5+i*10)] = bids[worker,i];
finaltable[worker, (shiftNum+6+i*10)] = bids[worker,i];
indexTable = np.argsort(finaltable, axis=0)
print(finaltable);
return finaltable;
rank_bids = numba.jit('float64[:,:](float64[:,:], float64[:,:], int64, float64)', nopython=True)(rankbids);
Run Code Online (Sandbox Code Playgroud)
似乎 numpy 不允许在 numba 函数中使用 Nd 数组进行 argsort?我的问题是,是否有人能够在 jit 函数中使用它,也许可以向我展示我可以做些什么才能使用它!
np.argsort适用于 numba,但不适用于axis关键字。你可以这样写你的代码indexTable = np.argsort(finaltable, axis=0):
indexTable = np.empty_like(finaltable)
for j in range(indexTable.shape[1]):
indexTable[:, j] = np.argsort(finaltable[:, j])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
650 次 |
| 最近记录: |