This is not an answer per se, but it probably will be faster due to using numpy rather than python's for loop.
First, you want to perform some binning:
>> bins = np.digitize(t, z) - 1 # minus 1 just to align our shapes
array([5, 5, 3, 1, 0, 2, 0, 5, 6, 4, 2, 0, 4, 5, 2])
This tells you in what bin each of your values goes. Next, define your patterns, in order:
>> patterns = np.array([
[0,0,0,0,0],
[0,0,0,0,1],
[0,0,0,1,0],
[0,0,0,1,1],
[0,0,1,0,0],
[0,0,1,0,1],
[0,0,1,1,0],
])
Now for some numpy magic, instead of appending/extending, create an array full of zeros (this should be almost always faster). This array will have shape (len(t), len(z)-1)
. Using this SO answer, we will also do one-hot encoding:
>> inds = np.zeros((len(t), len(z)-1))
>> inds[np.arange(len(t)), bins] = 1
>> inds
array([[0., 0., 0., 0., 0., 1., 0.],
[0., 0., 0., 0., 0., 1., 0.],
[0., 0., 0., 1., 0., 0., 0.],
.....,
[0., 0., 0., 0., 0., 1., 0.],
[0., 0., 1., 0., 0., 0., 0.]])
Finally, all we need to is a matrix multiplication
>> inds @ patterns
array([[0., 0., 1., 0., 1.],
[0., 0., 1., 0., 1.],
[0., 0., 0., 1., 1.],
....
[0., 0., 1., 0., 1.],
[0., 0., 0., 1., 0.]])
I did not perform a quality timing test, but from my minor experimentation here are my results:
Your loop: 17.7 µs ± 160 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
My implementation: 8.49 µs ± 125 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
Which may or may not scale well to larger datasets. Hope this helps :)
Edit: Following Alexander Lopatin's answer I was interested to see that my method was significantly slower. Upon further investigation one of the conclusions I arrived at was that numpy
's functions have some significant overhead which is not a cheap price to pay for few values of t
. For larger lists, the numpy overhead is insignificant, but the performance gain is not:

timings = {
10: [7.79, 24.1, 21.7],
16: [10.7, 29.9, 22.9],
24: [14.6, 40.5, 23.4],
33: [19.1, 48.6, 23.4],
38: [21.9, 55.9, 23.9],
47: [26.7, 66.2, 24.1],
61: [33, 79.5, 24.7],
75: [40.8, 92.6, 25.8],
89: [47.6, 108, 26.2],
118: [60.1, 136, 27.4],
236: [118, 264, 33.1],
472: [236, 495, 40.9],
1000: [657, 922, 52],
10000: [6530, 9090, 329]
}
Zoom:
