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