I want to insert zeros in a numpy array but in a different way that the numpy.insert function works. The numpy.insert function inserts every element before the position of the given index without caring about the other elements included in the same insertion. That is, the indexs given to the function refer to positions before the insertion. I would like a function that considers the indices after the insertion. Let me give an example:
If the input array is array(1, 2, 3, 4) and the indices are [2, 5], the output array should be array(1, 2, 0, 3, 4, 0).
A non-vectorized way to do it would be:
for index in indices:
input_array = np.insert(input_array, index, 0)
I am looking for a vectorized way to do this, but I cannot find it.
indices = np.array([2, 6])? - Divakar