Python Sympy Permutation().array_form方法
在sympy.combinatorics.Permutation().array_form方法的帮助下,我们可以通过sympy.combinatorics.Permutation().array_form方法从多维数组或矩阵中得到线性阵列。
语法: sympy.combinatorics.Permutation().array_form
返回:返回一个单维数组。
例子#1 :
在这个例子中,我们可以看到,通过使用sympy.combinatorics.Permutation().array_form方法,我们能够从矩阵或多维数组中获得线性数组。
# import sympy and Permutation
from sympy.combinatorics.permutations import Permutation
from sympy import *
Permutation.print_cyclic = False
# Using sympy.combinatorics.partitions.Permutation().array_form method
gfg = Permutation([ [1, 2, 3], [21, 32, 44] ])
print(gfg.array_form)
输出 :
[0, 2, 3, 1, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 32, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 44, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 21]
例子#2 :
# import sympy and Permutation
from sympy.combinatorics.permutations import Permutation
from sympy import *
Permutation.print_cyclic = False
# Using sympy.combinatorics.partitions.Permutation().array_form method
gfg = Permutation([ [1, 2], [3, 4], [5] ])
print(gfg.array_form)
输出 :
[0, 2, 1, 4, 3, 5]