我尝试在Numba中使用以下函数:
@numba.njit def nested_sort(s): return sorted(s, key=lambda x: (x[1], x[2])) s = [[1, 3, 11], [2, 3, 19], [3, 2, 18], [4, 2, 9]] nested_sort(s)
但是,Numba不支持此功能。我正在寻找这个函数的一个变体,它将在没有Python模式下与Numba一起工作。
alen0pnh1#
你想要的是np.lexsort。它根据指定的键序列的 * 反向 * 顺序进行排序。This question也可能是相关的。
np.lexsort
sorted_s = s[np.lexsort((s[:,2], s[:,1]))]
编辑:你似乎已经编辑了你的问题,你不再寻找一个 numpy 答案。我还是把这个答案留在这里。
1条答案
按热度按时间alen0pnh1#
你想要的是
np.lexsort
。它根据指定的键序列的 * 反向 * 顺序进行排序。This question也可能是相关的。编辑:你似乎已经编辑了你的问题,你不再寻找一个 numpy 答案。我还是把这个答案留在这里。