How do negative time offsets map to fixed-width buckets?

floor_divide rounds the quotient downward. With a positive bucket width this partitions the line into half-open intervals.

numpy.floor_divide in practice

With ten-second buckets, minus one second belongs to bucket minus one and zero belongs to bucket zero. Truncating the fractional part would misassign the negative offset.

import numpy as np
np.floor_divide([-11,-1,0,9,10],10)

Result [-2, -1, 0, 0, 1]

中文

负时间偏移如何分配到固定桶?

floor_divide 对商向负无穷取整。配合正桶宽,每个桶可覆盖左闭右开的连续区间。

numpy.floor_divide 算例

以十秒为桶,-1 秒属于编号 -1,而零秒属于编号 0。简单截去小数会把 -1 秒错误地归入零号桶。

import numpy as np
np.floor_divide([-11,-1,0,9,10],10)

结果 [-2, -1, 0, 0, 1]

References / 参考来源

Keep reading / 继续阅读