I want to assign a value to some segments of an array. I've got indexes of the segments as tuples (start_idx, end_idx). Segments may overlay or be sub-segments of each other.
a = np.zeros(12)
segments = np.array([(0, 3), (1, 2), (6, 8), (8, 10)])
a[segments] = 1
The results is:
a
>> array([1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0])
How can I mask all segments to get this output:
a
>> array([1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0])
[3]element is wrong?! Shouldn't it be0?10be handled then? Normally it would be anIndexErrorat least fora = np.zeros(10).a = np.zeros(12)as the final output seems to have 12 elems.