I create a normal python list
a = [[[1,2],[3,4]],[[5,6],[7,8]],[[9,10],[11,12]]]
Now I want to shift the first row of each 2x2 array to the previous 2x2 array, wrapping the first back to the last. I use the following unpacking assignment statement:
a[0][0],a[1][0],a[2][0] = a[1][0],a[2][0],a[0][0]
I get the following, which is what I want
print(a)
[[[5, 6], [3, 4]], [[9, 10], [7, 8]], [[1, 2], [11, 12]]]
Now, I do the same thing, this time, using numpy arrays
b = np.arange(1,13).reshape((3,2,2))
print(b)
[[[ 1 2]
[ 3 4]]
[[ 5 6]
[ 7 8]]
[[ 9 10]
[11 12]]]
The shift is the same as before but using numpy indexing syntax
b[0,0],b[1,0],b[2,0] = b[1,0],b[2,0],b[0,0]
print(b)
[[[ 5 6]
[ 3 4]]
[[ 9 10]
[ 7 8]]
[[ 5 6]
[11 12]]]
As you can see, this assignment left the first and last 2x2 arrays with the same first row.
Would you expect this behavior difference? Why does numpy do this but not the regular list type? How could the numpy assignment be done to result in the same result as the list?