Hi
In the following snippet, each cell of CellsToDuplicateVariableTimes is repeated the number of times defined in NumberOfReplicationPerCell : i’m sure there’s a more relevant way to proceed => how would you do?
Thanks
Paul
|
1
2
3
4
5
6
7
8
9
|
CellsToDuplicateVariableTimes = np.array([2, 6, 8, 10, 11])NumberOfReplicationPerCell = np.array([4, 3, 2, 5, 1])New = np.zeros(0, dtype = int)n = np.shape(CellsToDuplicateVariableTimes)[0]List = [np.repeat(CellsToDuplicateVariableTimes[i], NumberOfReplicationPerCell[i]) for i in range(n)]for arr in List: New = np.hstack((New, arr))print(f"New = {New}") |
Output:
New = [ 2 2 2 2 6 6 6 8 8 10 10 10 10 10 11]