如何找到np.partition()的实际实现?

时间:2019-08-20 12:15:22

标签: python numpy

要了解how numpy.partition() works,我正在尝试阅读source code

if axis is None:
    # flatten returns (1, N) for np.matrix, so always use the last axis
    a = asanyarray(a).flatten()
    axis = -1
else:
    a = asanyarray(a).copy(order="K")
a.partition(kth, axis=axis, kind=kind, order=order)
return a

只是使用numpy.asanyarray()封装输入,然后调用自身。

这似乎不是实际的实现,如何找到np.partition()的实际实现?

1 个答案:

答案 0 :(得分:4)

正如您所指出的,np.partition使用partition的方法ndarray,该方法本身是用C编写的,名称为array_partitionYou can find its source here。如果您查看源代码,将会发现它内部使用了另一个C函数PyArray_Partitionwhich can be found here

要查找哪个源文件包含哪个功能,您始终可以使用GitHub的搜索栏搜索特定的仓库:-)