In [178]: cell = np.array([1, 4, 4, 5, 5, 2, 5, 1, 1, 5])
In [179]: place = np.argwhere(cell == np.amax(cell)).flatten().tolist()
In [180]: place
Out[180]: [3, 4, 6, 9]
In [181]: np.insert(cell, place, 0)
Out[181]: array([1, 4, 4, 0, 5, 0, 5, 2, 0, 5, 1, 1, 0, 5])
In [182]: np.concatenate([cell[:3],[0],cell[3:4],[0],cell[4:6],[0],cell[6:9],[0] ,cell[9:]])
Out[182]: array([1, 4, 4, 0, 5, 0, 5, 2, 0, 5, 1, 1, 0, 5])
Constructing the concatante list could be generalized with some sort of list iteration over the place values. Details are left to the reader.
insert, with multiple insertions, uses a mask approach, which we can reverse engineer:
Where did it insert the 0s?
In [193]: res = np.insert(cell, place, 0)
In [194]: np.where(res==0)
Out[194]: (array([ 3, 5, 8, 12], dtype=int32),)
That's the same as adding 0,1,2,3 to place:
In [195]: np.arange(n)+place
Out[195]: array([ 3, 5, 8, 12])
make a target array and mask array:
In [196]: out = np.zeros(len(cell)+n, dtype=cell.dtype)
In [197]: mask = np.ones(len(out), dtype=bool)
use the mask to define where we insert the original values
In [198]: mask[Out[195]]=False
In [199]: out[mask] = cell
In [200]: out
Out[200]: array([1, 4, 4, 0, 5, 0, 5, 2, 0, 5, 1, 1, 0, 5])
Since the insertion value is 0, we don't need to do anything more.
I suggested in the previous answer that concatenate was faster than insert because insert is more general and takes more time to set things up. That may be the case as well. But I don't expect a bit improvement in time.
Generalized concatenate
In [235]: catlist = [cell[:place[0]],[0]]
In [236]: for i in range(n-1):
...: catlist.append(cell[place[i]:place[i+1]])
...: catlist.append([0])
...:
In [237]: catlist.append(cell[place[-1]:])
In [238]: np.concatenate(catlist)
Out[238]: array([1, 4, 4, 0, 5, 0, 5, 2, 0, 5, 1, 1, 0, 5])
placeis empty. What's that command supposed to do forplace?np.insert(e.g. source like on docs). It uses different strategies depending the number of insertion points. While the possibilities are numerous, the basic principles are simple.