I have numpy array as follows:

train_x = [[1,2,3,0,0], [2,5,0,0,0], [2,3,0,0,0], [0,0,0,0,0], [0,0,0,0,0,0]]


Now, I would like to transform it to as shown below:

new_train_x = [[0,0,0,0,0],[0,0,0,0,0,0],[0,0,1,2,3],[0,0,0,2,5],[0,0,0,2,3]]


I tried writing manually. The length of such list is huge. But it is time consuming.

I would like to know the efficient and short code for this (manually takes time).

• it is not possible if you dont konw the amount of padding of each input or if padding is fixed and consistent Aug 13 at 18:00

So assuming that the padding is the same length and the shape of the array is consistent you can do something below:

        import numpy as np
train_x = np.array([[1,2,3,0,0], [2,5,0,0,0], [2,3,0,0,0], [0,0,0,0,0], [0,0,0,0,0,0]])
stringX = ''
for i in train_x:
for s in i:
stringX += str(s)
subStrX = stringX[0:12]

counter = 0
internalCounter = 0
newStr = ''
newLst = np.empty(shape=([5,5]),dtype=str)
while counter < 25: