Skip to content
Advertisement

Numpy Zero Padding to match a certain shape

I have a file with arrays or different shapes. I want to zeropad all the array to match the largest shape. The largest shape is (93,13).

To test this I have the following code:

testarray = np.ones((41,13))

how can I zero pad this array to match the shape of (93,13)? And ultimately, how can I do it for thousands of rows?

Edit: The solution was found in the comments:

for index, array in enumerate(mfcc):
    testarray = np.zeros((93,13))
    for index,row in enumerate(array):
        for i in range(0,len(row)-1):
            testarray[index][i]= row[i]
            mfcc[index] = testarray

Advertisement

Answer

You could do like this. array is your original array and in this case just for testcase. Just use your own one.

import numpy as np
array  = [[None] * 10]*10
#print(array)
testarray = np.zeros((93,13))
for index,row in enumerate(array):
    for i in range(0,len(row)-1):
        testarray[index][i]= row[i]
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement