擅长:python、mysql、java
<p>像这样的怎么样?这会加速你的计算吗?你知道吗</p>
<pre><code>import numpy as np
import itertools
a = np.array([0,1,2])
b = np.array([3,4,5])
c = np.array([6,7,8])
combination = [a, b, c]
added = []
# Getting the required permutations
for p in itertools.permutations(range(len(a)), len(a)):
# Using iterators and generators speeds up your calculations
# zip(combination, p) pairs the index to the correct lists
# so for p = (0, 1, 2) we get (a,0), (b, 1), (c, 2)
# now find sum of (a[0], b[1], c[2]) and appened to added
added.append(sum(i[j] for i, j in zip(combination, p)))
# print added and total sum
print(added)
print(sum(added))
</code></pre>