If I have a square matrix as a nested list in python I can split it up into several equal sized boxes and create a new list where each element is a list of the numbers in one of those boxes. E.g.
a = [[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15 ,16]]
b = [[a[0][0], a[0][1], a[1][0], a[1][1]],
[a[0][2], a[0][3], a[1][2], a[1][3]],
[a[2][0], a[2][1], a[3][0], a[3][1]],
[a[2][2], a[2][3], a[3][2], a[3][3]]]
Is there an easier way to do this? Is there a way to set this up as a function which I can apply to matrices of different sizes and also specify the size of the boxes?
The following is equivalent to what you have and a bit more concise:
Or an equivalent list comprehension: