Как вариант:
import numpy as np
A = [[1,2], [3,4]]
def pad_el(el):
return np.stack(
(
np.zeros(3),
np.pad([el], 1, mode='constant'),
np.zeros(3)
), axis=1)
out_array = []
for i in range(len(A)):
row = []
for j in range(len(A[i])):
if len(row) == 0:
row = pad_el(A[i][j])
else:
row = np.block([row, pad_el(A[i][j])])
if len(out_array) == 0:
out_array = row
else:
out_array = np.vstack((out_array, row))
print(out_array)
[[0. 0. 0. 0. 0. 0.]
[0. 1. 0. 0. 2. 0.]
[0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0.]
[0. 3. 0. 0. 4. 0.]
[0. 0. 0. 0. 0. 0.]]
Для
A = [[1,2,3], [3,4,5], [6,7,8]]
[[0. 0. 0. 0. 0. 0. 0. 0. 0.]
[0. 1. 0. 0. 2. 0. 0. 3. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0.]
[0. 3. 0. 0. 4. 0. 0. 5. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0.]
[0. 6. 0. 0. 7. 0. 0. 8. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0.]]