在numpy中,您可以将(向量化)顺序定义函数应用于数组,然后用于
np.argsort对结果进行排序。
这比C ++版本的空间效率低,但是这通常是通过numpy实现性能的方式。
import numpy as npdef myfn(x): return np.sin(x[:, 1]) # example: sort by the sine of the second columna = np.random.randn(10, 4)predicate = myfn(a) # not sure if predicate is the best name for this variableorder = np.argsort(predicate)a_sorted = a[order]



