python计算组合数_Python实现的排列组合计算操作示例
生活随笔
收集整理的這篇文章主要介紹了
python计算组合数_Python实现的排列组合计算操作示例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Python實現的排列組合計算操作示例
本文實例講述了Python實現的排列組合計算操作。分享給大家供大家參考,具體如下:
1. 調用 scipy 計算排列組合的具體數值
>> 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)
# 可迭代對象
>> 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)]
完 謝謝觀看
總結
以上是生活随笔為你收集整理的python计算组合数_Python实现的排列组合计算操作示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: DNF经验心得:如何让你成为真正的商人
- 下一篇: 如何在树莓派上进行python编程_《树