I want all possible single right shift arrays:
def gen(total):
rot = []
init = [0]*total
init[0] = 1
print init
rot.append(init)
for i in range(total-1):
init[i] = init[i] - init[i+1]
init[i+1] = init[i] + init[i+1]
init[i] = init[i+1] - init[i]
print init
rot.append(init)
return rot
rot = gen(8)
print rot
This prints
[1, 0, 0, 0, 0, 0, 0, 0]
[0, 1, 0, 0, 0, 0, 0, 0]
[0, 0, 1, 0, 0, 0, 0, 0]
[0, 0, 0, 1, 0, 0, 0, 0]
[0, 0, 0, 0, 1, 0, 0, 0]
[0, 0, 0, 0, 0, 1, 0, 0]
[0, 0, 0, 0, 0, 0, 1, 0]
[0, 0, 0, 0, 0, 0, 0, 1]
I want this to be list of lists. I initialise an array rot but appending to it creates same rows
[[0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1]]
How to handle this issue?
PS: I don't want to use numpy like numpy.eye(8)
xorversion) that is not very readable and it breaks down with large integers. Python already a syntax for swapping values:init[i], init[i + 1] = init[i + 1], init[i].