Python 排列组合的计算

                       

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

A 2 3 =6,(32)=3 A32=6,(32)=3

>> from scipy.special import comb, perm>> perm(3, 2)6.0>> comb(3, 2)3.0
   
   
  • 1
  • 2
  • 3
  • 4
  • 5

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)]
   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

猜你喜欢

转载自blog.csdn.net/qq_43679627/article/details/86656939