Where do the left and right insertion points of a tied timestamp fall?

searchsorted finds insertion positions in sorted data. Left and right modes identify the two ends of an equal-value run.

numpy.searchsorted in practice

In timestamps [1,3,3,8], the half-open range [1,3) contains both events at time three. That interpretation depends on the sorted-input condition.

import numpy as np
[np.searchsorted([1,3,3,8],3,side=s) for s in ('left','right')]

Result [1, 3]

中文

重复时间戳的左右插入点有何区别?

searchsorted 在有序数组中寻找保持排序的插入位置。左右模式分别定位相等区段的两端。

numpy.searchsorted 算例

在 [1,3,3,8] 中查找时间 3,区间 [1,3) 正好圈出两条记录。输入若未排序,这种区间解释就失效。

import numpy as np
[np.searchsorted([1,3,3,8],3,side=s) for s in ('left','right')]

结果 [1, 3]

References / 参考来源

Keep reading / 继续阅读