I have a matrix with the shape (3*k, 3*l) (e.g.: k=2, l=1):
A = np.arange(18).reshape(6, 3)
array([[ 0,  1,  2],
       [ 3,  4,  5],
       [ 6,  7,  8],
       [ 9, 10, 11],
       [12, 13, 14],
       [15, 16, 17]])
Now I want to expand this to a matrix 3*k, 3*l*3 (e.g.: 6x9) while flipping the elements for every 3-sized blocks:
B = np.asarray([[ 0.,  3.,  6.,  1.,  4.,  7.,  2.,  5.,  8.],
                [ 6.,  0.,  3.,  7.,  1.,  4.,  8.,  2.,  5.],
                [ 3.,  6.,  0.,  4.,  7.,  1.,  5.,  8.,  2.],
                [ 9., 12., 15., 10., 13., 16., 11., 14., 17.],
                [15.,  9., 12., 16., 10., 13., 17., 11., 14.],
                [12., 15.,  9., 13., 16., 10., 14., 17., 11.]])
To expand the matrix, I used the Kronecker product (of numpy):
K = np.kron(A, np.ones(3))
array([[ 0.,  0.,  0.,  1.,  1.,  1.,  2.,  2.,  2.],
       [ 3.,  3.,  3.,  4.,  4.,  4.,  5.,  5.,  5.],
       [ 6.,  6.,  6.,  7.,  7.,  7.,  8.,  8.,  8.],
       [ 9.,  9.,  9., 10., 10., 10., 11., 11., 11.],
       [12., 12., 12., 13., 13., 13., 14., 14., 14.],
       [15., 15., 15., 16., 16., 16., 17., 17., 17.]])
On this matrix I want to flip the rows tripple-wise for every column, where the column index modulo 3 is not 0. I thought of multiplying with some kind of rotation matrices would help such as:
r0 = np.asarray([[1, 0, 0], 
                 [0, 1, 0], 
                 [0, 0, 1]])
r1 = np.asarray([[0, 1, 0], 
                 [0, 0, 1], 
                 [1, 0, 0]])
r2 = np.asarray([[0, 0, 1], 
                 [1, 0, 0], 
                 [0, 1, 0]])
R = np.asarray([r0, r1, r2])
But I didn't get the expected result. So my question is:
How to calculate flipping of tripple-wise rows?
or is there a better/faster way, to expand and tripple-wise flip the rows?