I have the vector:
x = 1,2,3,4,5,6,7
I would like to make it:
x = 1,2,3,0,0,0,4,5,6,0,0,7
inserting the element 0 into x
at the proper positions ind
. I happen to know that
ind = 4,5,6,10,11
In the problem, ind
is specified as the position of each inserted 0 in the new version of x
. This is a toy problem. In reality x
and ind
are 1000s of elements long, and memory is very tight.
I have seen some threads that seem related but they do not solve the problem. Given ind
, they would create
x = 1 2 3 4 0 5 0 6 0 7 0 0
which is wrong (it misinterprets the insertion points).