Gurkirt:

for i in range(transition_matrix .shape[0]):
for j in range(transition_matrix .shape[0]):
if transition_matrix[i,j]>0:
final_fm[:, count, :256] = fm1[:, i, :]
final_fm[:, count, 256:] = fm2[:, j, :]
count += 1


It’s slow because you are doing this I think. Loops in python are slow.