Let's say I have this numpy array :
first_array = [[1. 0. 0. 0. 0.]
[1. 0. 0. 0. 0.]
[0. 1. 0. 0. 0.]
[0. 0. 1. 0. 0.]
[0. 0. 1. 0. 0.]
[0. 0. 1. 0. 0.]
[0. 0. 0. 0. 1.]]
and I have this 2 lists :
index_start = [50, 80, 110, 120, 150, 180, 200]
index_end= [70, 90, 115, 140, 170, 190, 220]
I want to create a new 2D numpy output_array where I iterate by column first_array and duplicate each value of every row from an index_start to an index_end.
1st iteration - For example first_array[[1,1]] = 1, index_start[1] = 50 and index_end[1]=70 then the first column of my output_array will have the value 1 from index 50 to 70.
2nd iteration - Then first_array[[2,1]] = 1, index_start[2] = 80 and index_end[2]=90 then the first column of my output_array will have also the value 1 but from index 80 to 90.
3rd iteration - first_array[[2,3]] = 1, index_start[3] = 110 and index_end[3]=115 then the second column of my output_array will have the value 1 from index 110 to 115 and so on.
Here's what I have tried but this is giving me wrong result :
first_array = [[1, 0, 0, 0, 0,],
[1, 0, 0, 0, 0,],
[0, 1, 0, 0, 0,],
[0, 0, 1, 0, 0,],
[0, 0, 1, 0, 0,],
[0, 0, 1, 0, 0,],
[0, 0, 0, 0, 1,]]
index_start = [50, 80, 110, 120, 150, 180, 200]
index_end= [70, 90, 115, 140, 170, 190, 220]
last_index = max(index_start+index_end)
output_array = np.zeros((last_index, 5))
for i in range(len(index_start)):
for j in range(last_index):
for k in range(5):
output_array[index_start[i]:index_end[i]]=first_array[i][k]