如何在 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