收到此错误消息:
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:
在使用此代码时
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);
似乎numpy在numba函数中不允许将argsort与Nd数组一起使用? 我的问题是,是否有人可以在jit函数中使用它,也许还向我展示了我可以做些什么!
答案 0 :(得分:2)
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])