Python| Sympy Permutation().array_form 方法
借助sympy.combinatorics.Permutation().array_form
方法,我们可以使用sympy.combinatorics.Permutation().array_form
方法从多维数组或矩阵中得到线性数组。
Syntax : sympy.combinatorics.Permutation().array_form
Return : Return an array having single dimension.
示例 #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]