我正在尝试制作一个将二进制列表交错到数组中的函数。矩阵大小为 10 行 x 9 列,初始化为None
. 这些位一次被送入矩阵,第一个输入位被送入 (0,0)。这些位被送入(前一行 + 7)模 10,当列满时,列向右移动,第 0 列填充下一组位。但是,我遇到了列填充循环的问题。零列中的每一行都被设置为相同的值!
这是我到目前为止所拥有的:
>>> row = 0
>>> interleave_row = [None,None,None,None,None,None,None,None,None]
>>> interleave_matrix = [interleave_row,interleave_row,interleave_row,interleave_row,interleave_row,interleave_row,interleave_row,interleave_row,interleave_row,interleave_row]
这会产生一个矩阵,如下所示:
[None, None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None, None]]
>>> input = [0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0]
>>> for i in range(0,10):
interleave_matrix[row][0] = input[i]
row = (row+7)%10
这产生:
[1, None, None, None, None, None, None, None, None],
[1, None, None, None, None, None, None, None, None],
[1, None, None, None, None, None, None, None, None],
[1, None, None, None, None, None, None, None, None],
[1, None, None, None, None, None, None, None, None],
[1, None, None, None, None, None, None, None, None],
[1, None, None, None, None, None, None, None, None],
[1, None, None, None, None, None, None, None, None],
[1, None, None, None, None, None, None, None, None]]
它应该如下所示:
[0, None, None, None, None, None, None, None, None],
[1, None, None, None, None, None, None, None, None],
[0, None, None, None, None, None, None, None, None],
[0, None, None, None, None, None, None, None, None],
[0, None, None, None, None, None, None, None, None],
[0, None, None, None, None, None, None, None, None],
[1, None, None, None, None, None, None, None, None],
[1, None, None, None, None, None, None, None, None],
[1, None, None, None, None, None, None, None, None]]
我有一个菜鸟时刻吗?我知道行增量工作正常,因为我自己循环了它。什么可能导致这种奇怪的行为?
编辑:我只是尝试循环遍历前四位(保证以 0 位结束),它没有将整行设置为该位,它只是将整行设置为 1。越来越奇怪了……