Locate the insertion point
for x in a to maintain sorted order. The parameters lo and hi may be
used to specify a subset of the list which should be considered; by
default the entire list is used. If x is already present in a, the
insertion point will be before (to the left of) any existing entries.
The return value is suitable for use as the first parameter to
list.insert() assuming that a is already sorted.
The returned insertion point i partitions the array a into two halves
so that all(val < x for val in a[lo:i]) for the left side and all(val >= x for val in a[i:hi]) for the right side.
对于纯python解决方案,有^{} 模块:
或与numpy:
如注释中所述,对于要排序的
l
,我们可以使用np.searchsorted
-或与
np.digitize
-相关问题 更多 >
编程相关推荐