admin管理员组文章数量:1323203
Below is a small part of what I'm trying to run, it gets stuck on the final line
k=2
elements = [i for i in np.arange(k)]
Sk = PermutationGroup([Permutation(list(perm)) for perm in itertools.permutations(elements)])
factorial = int(sp.special.factorial(k))
for i in np.arange(factorial):
trace_list = np.zeros(Sk[i].cycles)
...
The problem is that the list index is out of range because Sk doesn't seem to include the identity element when you list all of the elements:
k=2
elements = [i for i in np.arange(k)]
Sk = PermutationGroup([Permutation(list(perm)) for perm in itertools.permutations(elements)])
print(Sk)
PermutationGroup([(0 1)])
I know that the identity exists as Sk.identity
, but I just want to be able to simply loop through Sk
without having to put special cases for every time the identity is needed. Is there a way to do this?
Below is a small part of what I'm trying to run, it gets stuck on the final line
k=2
elements = [i for i in np.arange(k)]
Sk = PermutationGroup([Permutation(list(perm)) for perm in itertools.permutations(elements)])
factorial = int(sp.special.factorial(k))
for i in np.arange(factorial):
trace_list = np.zeros(Sk[i].cycles)
...
The problem is that the list index is out of range because Sk doesn't seem to include the identity element when you list all of the elements:
k=2
elements = [i for i in np.arange(k)]
Sk = PermutationGroup([Permutation(list(perm)) for perm in itertools.permutations(elements)])
print(Sk)
PermutationGroup([(0 1)])
I know that the identity exists as Sk.identity
, but I just want to be able to simply loop through Sk
without having to put special cases for every time the identity is needed. Is there a way to do this?
1 Answer
Reset to default 0Key Adjustments:
Add Identity Permutation: Manually include the identity permutation in the list of permutations using
all_permutations.append(identity_perm)
Iterate Smoothly: Ensure the iteration through
Sk
properly accounts for the identity permutation, eliminating any potential index errors.
By doing this, the identity permutation becomes a regular part of Sk
, so you won’t need to handle it separately.
本文标签: pythonHow to loop through a permutation group in SymPy including the identityStack Overflow
版权声明:本文标题:python - How to loop through a permutation group in SymPy including the identity - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742122691a2421795.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论