def commutation_matrix(p, q):
 K = np.eye((p * q))
 indices = np.arange((p * q)).reshape((p, q), order='F')
 return K.take(indices.ravel(), axis=0)

def commutation_matrix ( p , q ) : K = np . eye ( ( p * q ) ) indices = np . arange ( ( p * q ) ) . reshape ( ( p , q ) , order = 'F' ) return K . take ( indices . ravel ( ) , axis = 0 )
create the commutation matrix k_{p .