Python中的SymPy Partition.prev_lex()

Python中的SymPy Partition.prev_lex()

Partition.prev_lex() : prev_lex()是一个Sympy Python库函数,用于返回前一个整数分区,n的列序。如果分区是[1,…,1],这个排序就会环绕[n]。

语法 : sympy.combinatorics.partitions.Partition.prev_lex()
返回:之前的整数分区,n为lexicographical顺序。

代码#1:prev_lex()示例

# Python code explaining
# SymPy.prev_lex()

# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.partitions import IntegerPartition

# Using from sympy.combinatorics.partitions.Partition.prev_lex() method 
p = IntegerPartition([312, 121, 14, 5])

print('p : ', p)
print('\nPrevious Integer : ', p.prev_lex())

输出 :

p : [312, 121, 14, 5]
Previous Integer : [312, 121, 14, 4, 1]

代码#2:prev_lex()示例

# Python code explaining
# SymPy.prev_lex()

# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.partitions import IntegerPartition

# Using from sympy.combinatorics.partitions.Partition.prev_lex() method 
p = IntegerPartition([1, 312, 121, 14, 
                      34, 56, 32])

print('p : ', p)
print('\nPrevious Integer : ', p.prev_lex())

输出 :

p : [312, 121, 56, 34, 32, 14, 1]
Previous Integer : [312, 121, 56, 34, 32, 13, 2]

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程