0
我正在尋找從1D列表中以最pythonic方式填充3x3矩陣。用M矩陣填充M與1D列表python
所以從第一轉變爲第二
[1,2,3,4,5,6,7,8,9]
[ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]
到目前爲止,我可以填寫第一次作爲這樣的:
l = [1,2,3,4,5,6,7,8,9]
m = [[l[y] for y in range(3)] for x in range(3)]
但是這給
[['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9']]
看到numpy.reshape https://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html –