# using of M.permute_rows_and_columns

Hi

I am aware that with this question my Karma will drop a notch !

despite explanations

I don't understand the use of M.permute_rows_and_columns() how to use it to do this function below ?

M = matrix(ZZ,[[1,0,0,0,0],[0,2,0,0,0],[0,0,3,0,0],[0,0,0,4,0],[0,0,0,0,5]])

def permRandC(a,b) :
"permute row and column a,b"
Mc=copy(M)
Mc[:,a]=M[:,b]
Mc[:,b]=M[:,a]
Mr=copy(Mc)
Mr[a,:]=Mc[b,:]
Mr[b,:]=Mc[a,:]
return Mr

show(permRandC(0,1))

edit retag close merge delete

Sort by ยป oldest newest most voted

The following yields the same result as your function perRandC:

G = SymmetricGroup(5) # create the symmetric group on 5
perm = G((1,2)) # create the permutation (1, 2) in G, i.e. perm just swaps 1 and 2
M.permute_rows_and_columns(perm, perm)
show(M)


G contains all possible permutations of {1,2,3,4,5}. Note that permute_rows_and_columns works with 1-based indices, i.e. since we want to swap the 0th and 1st row we have to use (1,2). Alternatively, using the same method as in the documentation, we could also do:

G = PermutationGroup(['(1,2)'])
perm = G.gens()[0]
M.permute_rows_and_columns(perm, perm)
show(M)


All three yield the same result.

more

thank you @philipp7

( 2021-09-01 13:26:37 +0100 )edit