I am trying to make a function to interleave a binary list into an array. The matrix size is 10 rows x 9 columns, initialized to None
. The bits are fed into the matrix one at a time, with the first input bit being fed into (0,0). The bits are fed into (previous row + 7) mod 10, and when the column is full, the column is moved to the right, and the column 0 is filled with the next set of bits.
However, I am running into a problem with the column fill loop. Every row in column zero is being set to the same value!
Here is what I have so far:
>>> 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]
This yields a matrix that looks like:
[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
This yields:
[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]]
It should look like this:
[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]]
Am I having a noob moment? I know the row increment is working fine, as I've looped it by itself. What could be causing such weird behaviour?
EDIT: I just tried looping through the first four bits (guaranteed to end on a 0 bit), and it's not setting the entire row to the bit, it's just setting the entire row to 1. It's getting more and more strange...
Answer posted by Pavel!
Your matrix actually contains N references to the same column. So when you modify a value in one column, this value is also modified in all other columns. Consider creating matrix another way to make independent columns: stackoverflow.com/q/2397141/6131611 stackoverflow.com/q/6667201/6131611
It was definitely a noob moment, but I got to learn from it! Thank you!