"as of" in numpy
Your best choice is numpy.searchsorted()
:
d1[numpy.searchsorted(t1, t2, side="right") - 1]
This will search the indices where the values of t2
would have to be inserted into t1
to maintain order. The side="right"
and - 1
bits are to ensure exactly the specified behaviour.
Edit: To get rows of NaNs where the condition t1[j] <= t2[i]
can't be satisfied, you could use
nan_row = numpy.repeat(numpy.nan, d1.shape[1])d1_nan = numpy.vstack((nan_row, d1))d2 = d1_nan[numpy.searchsorted(t1, t2, side="right")]