I have a 5x20 Matrix, I intend to use Matrix Function and Transformations like Fourier Transform which can only be used for Symmetric Matrix. How can I convert the 5x20 Matrix to 20x20 Matrix by Zero Padding?
Asked
Active
Viewed 416 times
0
-
can you paste your matrix as text in the question? Also, can pandas & numpy be used in the solution? – moys Oct 10 '19 at 05:16
-
suggest you to give a [minimal reproducible example](https://stackoverflow.com/a/20159305/2970853) and the expected output – henrywongkk Oct 10 '19 at 05:17
3 Answers
1
import numpy as np
a = np.array([[1,1,1,1],[2,2,2,2]])
b=np.zeros((20,20))
result = np.zeros_like(b)
x = 0
y = 0
result[x:a.shape[0],y:a.shape[1]] = a
print(result)
You can use the above logic to implement the padding.

Stan11
- 274
- 3
- 11
0
Are you using numpy? If you do you can do it by slicing the arrays
import numpy as np
random_array_5_20 = np.random.rand(5, 20)
padded_array_20_20 = np.zeros((20, 20))
padded_array_20_20[:5, :20] = random_array_5_20

Bruno Vermeulen
- 2,970
- 2
- 15
- 29
0
One more approach.
Here a
is the array that you already have.
import numpy as np
a = np.random.rand(5,20)
za = np.zeros((1, 20))
while a.shape[0] < 20:
a = np.concatenate((a,za))

moys
- 7,747
- 2
- 11
- 42