sympy.utilities.iterables.combinations() 替换? [英] sympy.utilities.iterables.combinations() with replacement?

查看:31
本文介绍了sympy.utilities.iterables.combinations() 替换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 sympy api 进行组合.

首先,组合没有替换 ...

from sympy.functions.combinatorial.numbers import nC从 sympy.utilities.iterables 导入组合nC('abc', 2)# >>>3列表(组合('abc',2))# >>>[('a', 'b'), ('a', 'c'), ('b', 'c')]

我现在想列出组合替换

nC('abc', 2, replacement=True)# >>>6

但是,combinations() 方法似乎不支持替换"参数?

初始化签名:组合(self,/, *args, **kwargs)文档字符串:组合(可迭代,r)-->组合对象返回迭代中元素的连续 r 长度组合.组合(范围(4),3)-->(0,1,2), (0,1,3), (0,2,3), (1,2,3)类型:类型

解决方案

是另一种方法

<块引用><块引用>

初始化签名:sym​​py.utilities.iterables.combinations_with_replacement(self,/, *args, **kwargs)文档字符串:
combinations_with_replacement(iterable, r) -->combinations_with_replacement 对象

返回迭代中元素的连续r长度组合允许单个元素连续重复.组合_with_replacement('ABC', 2) --> AA AB AC BB BC CC类型:类型

I'm experimenting with the sympy api for combinations.

First, combinations without replacement ...

from sympy.functions.combinatorial.numbers import nC
from sympy.utilities.iterables import combinations

nC('abc', 2)
# >>> 3

list(combinations('abc', 2))
# >>> [('a', 'b'), ('a', 'c'), ('b', 'c')]

I would now like to list the combinations with replacement

nC('abc', 2, replacement=True)
# >>> 6

However, the combinations() method doesn't seem to support a 'replacements' argument?

Init signature: combinations(self, /, *args, **kwargs)
Docstring:     
combinations(iterable, r) --> combinations object

Return successive r-length combinations of elements in the iterable.

combinations(range(4), 3) --> (0,1,2), (0,1,3), (0,2,3), (1,2,3)
Type:           type

解决方案

It is a different method

Init signature: sympy.utilities.iterables.combinations_with_replacement(self, /, *args, **kwargs) Docstring:
combinations_with_replacement(iterable, r) --> combinations_with_replacement object

Return successive r-length combinations of elements in the iterable allowing individual elements to have successive repeats. combinations_with_replacement('ABC', 2) --> AA AB AC BB BC CC Type: type

这篇关于sympy.utilities.iterables.combinations() 替换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆