numba \ jit不允许在nopython模式下使用np argsort [英] numba\jit doesn't allow the use of np argsort in nopython mode

查看:327
本文介绍了numba \ jit不允许在nopython模式下使用np argsort的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

收到此错误消息:

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:


在使用此代码时


While using this code

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函数中使用它,也许还向我展示了我可以做些什么!

It seems that numpy does't allow argsort with Nd arrays in numba functions? My question is if anyone has been able to use it within a jit function and perhaps show me what I could possible do to be able to use it!

推荐答案

np.argsort在numba中有效,但axis关键字无效.您可以这样编写代码indexTable = np.argsort(finaltable, axis=0):

np.argsort works in numba, but not the axis keyword. You could write your code indexTable = np.argsort(finaltable, axis=0) like this:

indexTable = np.empty_like(finaltable)
for j in range(indexTable.shape[1]):
    indexTable[:, j] = np.argsort(finaltable[:, j])

这篇关于numba \ jit不允许在nopython模式下使用np argsort的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆