So, do you have a different repetition array for each row? But the total number of repetitions per line is the same?
Just do repeat on flattened arrays and get back to the correct number of lines.
In [529]: np.repeat(arr,rep.flat) Out[529]: array([10, 10, 10, 24, 24, 24, 24, 10, 10, 24, 24, 24, 24, 1]) In [530]: np.repeat(arr,rep.flat).reshape(2,-1) Out[530]: array([[10, 10, 10, 24, 24, 24, 24], [10, 10, 24, 24, 24, 24, 1]])
If the repetitions of each line change, we are faced with the problem of filling lines of variable length. This arises in other matters. I donβt remember all the details, but I think the solution goes along this line:
Modify rep so the numbers are different:
In [547]: rep Out[547]: array([[3, 2, 2, 0, 0, 0, 0, 0, 0, 0], [2, 2, 2, 1, 0, 2, 0, 0, 0, 0]]) In [548]: lens=rep.sum(axis=1) In [549]: lens Out[549]: array([7, 9]) In [550]: m=np.max(lens) In [551]: m Out[551]: 9
create goal:
In [552]: res = np.zeros((arr.shape[0],m),arr.dtype)
create an indexing array - details should be developed:
In [553]: idx=np.r_[0:7,m:m+9] In [554]: idx Out[554]: array([ 0, 1, 2, 3, 4, 5, 6, 9, 10, 11, 12, 13, 14, 15, 16, 17])
flat indexed assignment:
In [555]: res.flat[idx]=np.repeat(arr,rep.flat) In [556]: res Out[556]: array([[10, 10, 10, 24, 24, 24, 24, 0, 0], [10, 10, 24, 24, 24, 24, 1, 1, 1]])