I have two arrays, say,
n = [1,2,3,4,5,6,7,8,9]
nc = [3,0,2,0,1,2,0,0,0]
The nonzero elements in nc are ncz = [3,2,1,2]. The elements in n corresponding to non zero elements in nc are p = [1,3,5,6]. I need to create a new array with elements of p[1:] inserted after ncz.cumsum()[:-1]+1 i.e after [4,6,7]
Is there any way to do this without using np.insert or a for loop?
Suppose I have m such pairs of arrays. Would I be able to do the same thing for each pair without using a loop? The resulting arrays can be zero padded to bring them to the same shape.
The result would be [1, 2, 3, 4, 3, 5, 6, 5, 7, 6, 8, 9]
To do it using np.insert, one would do:
n = np.array([1,2,3,4,5,6,7,8,9])
nc = np.array([3,0,2,0,1,2,0,0,0])
p1 = n[nc.nonzero()][1:]
ncz1 = nc[nc.nonzero()][:-1].cumsum()
result = np.insert(n,ncz1+1,p1)
I know how to do this using numpy insert operation, but I need to replicate it in theano and theano doesn't have an insert op.