Python 一个变量上的itertools置换
我有这个公式Python 一个变量上的itertools置换,python,arrays,math,permutation,itertools,Python,Arrays,Math,Permutation,Itertools,我有这个公式 x*A+y*B+z*C x、 y,z是变量 A、 B,C是常数 我想对这个公式应用所有可能的排列,并存储每个结果 对于偶数的排列,这是相当简单的 from itertools import permutations perm = permutations([1, 2,3]) [(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)] # ["1 * A " + 2 * B +
x*A+y*B+z*C
x、 y,z是变量
A、 B,C是常数
我想对这个公式应用所有可能的排列,并存储每个结果
对于偶数的排列,这是相当简单的
from itertools import permutations
perm = permutations([1, 2,3])
[(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)]
# ["1 * A " + 2 * B + 3 * C], -->append
# ["1 * A " + 3 * B + 2 * C], --->append
# ............
如何将其应用于非均匀排列数组,如
perm=置换([1,2,3,4,5])
?有一个可选的第二个参数,用于选择每个排列的大小:
perm=permutations([1,2,3,4,5],r=3)
结果:
[(1,2,3)、(1,2,4)、(1,2,5)…]