Ask Your Question
1

using of M.permute_rows_and_columns

asked 2021-09-01 09:35:21 +0200

ortollj gravatar image

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-09-01 13:05:34 +0200

philipp7 gravatar image

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.

edit flag offensive delete link more

Comments

thank you @philipp7

ortollj gravatar imageortollj ( 2021-09-01 13:26:37 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-09-01 09:35:21 +0200

Seen: 167 times

Last updated: Sep 01 '21