I want to have the permutation for this symmetric matrix, if we move the the second column to the third the second row also should go to the third row.
array([[ 0. , 0.06377803, 0.1157737 , 0.19542195],
[ 0.06377803, 0. , 0.14754803, 0.23185761],
[ 0.1157737 , 0.14754803, 0. , 0.0843134 ],
[ 0.19542195, 0.23185761, 0.0843134 , 0. ]])
This is code for permutation on a list:
import numpy as np
x=[]
def perm(a, k=0):
if k == len(a):
x.extend(a)
# print (a )
else:
for i in range(k, len(a)):
a[k], a[i] = a[i] ,a[k]
perm(a, k+1)
a[k], a[i] = a[i], a[k]
perm([0,1,2,3])
a=np.asarray(x).reshape((24,4))
print(a)
Output:
[[0 1 2 3]
[0 1 3 2]
[0 2 1 3]
[0 2 3 1]
[0 3 2 1]
[0 3 1 2]
[1 0 2 3]
[1 0 3 2]
[1 2 0 3]
[1 2 3 0]
[1 3 2 0]
[1 3 0 2]
[2 1 0 3]
[2 1 3 0]
[2 0 1 3]
[2 0 3 1]
[2 3 0 1]
[2 3 1 0]
[3 1 2 0]
[3 1 0 2]
[3 2 1 0]
[3 2 0 1]
[3 0 2 1]
[3 0 1 2]]
But I want to have the permutation for the above array which is 4*4. For simplicity if we have a 3*3 array, we want something like below which is K!=6 but when k=4 then we have to get k! which is 24 permutations