neuralib.util.segments.segment_index

neuralib.util.segments.segment_index(segs, t)[source]

find the index of segs where t located

segs : ---[---]---[---)[---]---
ret  :  -1  0   -2  1    2   -4

The following code are true

I = segment_index(S, T)
for i in np.nonzero(I >= 0)[0]:
    assert S[I[i], 0] <= t[i] <= S[I[i], 1]

for i in np.nonzero(I < 0)[0]:
    if -I[t] - 1 == 0:
        assert t[i] < S[-I[t] - 1, 0]
    elif -I[t] - 1 == len(S):
        assert S[-I[i] - 2, 1] < t[i]
    else:
        assert S[-I[i] - 2, 1] < t[i] < S[-I[t] - 1, 0]
Parameters:
  • segs (ndarray | tuple[float, float] | list[tuple[float, float]]) – (N, 2) T-value segments

  • t (ndarray) – (R,) T-value array

Returns:

(R,) N-value index array

Raises:

ValueErrorsegs has overlapped segments or not sorted

Return type:

ndarray