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:
JavaScript
x
2
1
testarray = np.ones((41,13))
2
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:
JavaScript
1
7
1
for index, array in enumerate(mfcc):
2
testarray = np.zeros((93,13))
3
for index,row in enumerate(array):
4
for i in range(0,len(row)-1):
5
testarray[index][i]= row[i]
6
mfcc[index] = testarray
7
Advertisement
Answer
You could do like this. array
is your original array and in this case just for testcase. Just use your own one.
JavaScript
1
8
1
import numpy as np
2
array = [[None] * 10]*10
3
#print(array)
4
testarray = np.zeros((93,13))
5
for index,row in enumerate(array):
6
for i in range(0,len(row)-1):
7
testarray[index][i]= row[i]
8