Python SymPy Permutation.cardinality()方法

Python SymPy Permutation.cardinality()方法

Permutation.cardinality() : cardinality()是一个sympy Python库函数,用于返回所有可能的排列组合的数量。

语法 : sympy.combinatorics.permutations.Permutation.cardinality()

返回:所有可能的排列组合的数量

代码#1:cardinality()示例

# Python code explaining
# SymPy.Permutation.cardinality()
  
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
  
# Using from sympy.combinatorics.permutations.Permutation.cardinality() method 
  
# creating Permutation
a = Permutation([[2, 0], [3, 1]])
  
b = Permutation([1, 3, 5, 4, 2, 0])
  
  
print ("Permutation a - cardinality form : ", a.cardinality)
print ("Permutation b - cardinality form : ", b.cardinality)

输出 :

Permutation a – cardinality form : 24

Permutation b – cardinality form : 720

代码#2:cardinality()实例–二维排列组合

# Python code explaining
# SymPy.Permutation.cardinality()
  
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
  
# Using from sympy.combinatorics.permutations.Permutation.cardinality() method 
  
# creating Permutation
a = Permutation([[2, 4, 0], 
                 [3, 1, 2],
                 [1, 5, 6]])
  
  
print ("Permutation a - cardinality form : ", a.cardinality)

输出 :

Permutation a – cardinality form : 5040

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程