python 排列組合


1. 調用 scipy 計算排列組合的具體數值

A23=6,(32)=3

>> from scipy.special import comb, perm >> perm(3, 2) 6.0 >> comb(3, 2) 3.0

2. 調用 itertools 獲取排列組合的全部情況數

>> from itertools import combinations, permutations
>> permutations([1, 2, 3], 2) <itertools.permutations at 0x7febfd880fc0> # 可迭代對象 >> list(permutations([1, 2, 3], 2)) [(1, 2), (1, 3), (2, 1), (2, 3), (3, 1), (3, 2)] >> list(combinations([1, 2, 3], 2)) [(1, 2), (1, 3), (2, 3)]


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM