如何在 Python 中使用 SciPy 计算排列和组合值?
SciPy 可用于确定关于两个值的排列和组合。
使用 SciPy 中的 'special' 类中的名为 'perm' 的函数。
‘perm’ 函数的语法
scipy.special.perm(N, k)

下面显示了对一组值执行排列。
示例
from scipy.special import perm
my_permute = perm(6, 2, exact = True)
print("The permutation of 6 and 2 is ")
print(my_permute)输出
The permutation of 6 and 2 is 30
解释
- 导入所需的库。
- 将参数传递给计算值的 'perm' 函数。
- 将值分配给变量。
- 此变量在控制台上显示。
在 SciPy 中计算两个值的组合
使用 SciPy 中的 'special' 类中的名为 'comb' 的函数。
‘comb’ 函数的语法
scipy.special.comb(N, k)

下面显示了对一组值执行排列。
示例
from scipy.special import comb
my_comb = comb(6, 2, exact = True)
print("The combination of 6 and 2 is ")
print(my_comb)输出
The combination of 6 and 2 is 15
解释
- 导入所需的库。
- 将参数传递给计算值的 'comb' 函数。
- 将值分配给变量。
- 此变量在控制台上显示。
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP