How to set some values with an interval in a vector to be another vector

I have a vector with size, for example, (1,16) which is x = [1,2,3,4,.....16] and another vector y = [1,2,3,4] whose size is( 1,4)

I want to set the values in the vector x with interval 4 to be the vector y. it means it will be like that x(1:4:16) = y ; In python, how can I do that?

The expected output is to be x = [1 2 3 4 2 6 7 8 3 10 11 12 4 14 15 16].

Answer

Try using slice assignment:

x[::len(y)] = y

And now:

print(x)

Will give:

[1, 2, 3, 4, 2, 6, 7, 8, 3, 10, 11, 12, 4, 14, 15, 16]