[Numpy-discussion] combinatorial operations on a pair of arrays
Damien Moore
damienlmoore@gmail....
Wed Nov 18 13:17:02 CST 2009
The title of this e-mail is probably misleading so let me just show some code:
from numpy import *
A=array([[1,2],[2,3],[3,4]])
B=array([[2,2],[3,3]])
C=zeros(A.shape)
for i in xrange(len(A)):
C[i]=sum(A[i]**B)
print C
What I want to do is eliminate the for loop and rely on numpy
internals, but I'm not sure how to do this most efficiently.
The fundamental aspect of the operation is that the array C is
constructed by applying each subarray B to each subarray of A (i.e.
all permutations) and then summing over a subset.
More information about the NumPy-Discussion
mailing list