网络编程
位置:首页>> 网络编程>> Python编程>> Python实现的排列组合计算操作示例

Python实现的排列组合计算操作示例

作者:Inside_Zhang  发布时间:2022-03-06 19:36:43 

标签:Python,排列组合,计算

本文实例讲述了Python实现的排列组合计算操作。分享给大家供大家参考,具体如下:

1. 调用 scipy 计算排列组合的具体数值

Python实现的排列组合计算操作示例


>> 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)]

PS:这里再为大家推荐几款计算工具供大家进一步参考借鉴:

在线一元函数(方程)求解计算工具:
http://tools.jb51.net/jisuanqi/equ_jisuanqi

科学计算器在线使用_高级计算器在线计算:
http://tools.jb51.net/jisuanqi/jsqkexue

在线计算器_标准计算器:
http://tools.jb51.net/jisuanqi/jsq

希望本文所述对大家Python程序设计有所帮助。

来源:http://blog.csdn.net/lanchunhui/article/details/51824602

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com