我真的是Python的新手,我一直在尝试遍历矩阵。我能够从矩阵输出2x2的块,但我想尝试在矩阵中滑动,但无法正确处理。
代码:
myMultidimensional = [[1,2,3,4,5],[5,10,15,20,25],[2,4,6,8,10]]
rows = 2
columns = 2
for x in range(rows):
for y in range(columns):
print(myMultidimensional[x][y], end=" ")
代码输出:1 2 5 10
想要的输出:
1 2 5 10
2 3 10 15等等...
答案 0 :(得分:0)
x = [[1, 2, 3, 4, 5], [5, 10, 15, 20, 25], [2, 4, 6, 8, 10]]
nrow = len(x)
ncol = len(x[0])
for i in range(nrow-1):
for j in range(ncol-1):
print(x[i][j], x[i][j+1], x[i+1][j], x[i+1][j+1])