Re: [Numpy-discussion] combinatorial operations on a pair of arrays

2009-11-18 Thread Damien Moore
Emanuelle, perfect! thanks. > (assuming "import numpy as np", which is considered as a better practice > as "from numpy import *") actually I normally just "import numpy" but I guess np is nicer to type and read... cheers, Damien ___ NumPy-Discussion

Re: [Numpy-discussion] combinatorial operations on a pair of arrays

2009-11-18 Thread Emmanuelle Gouillart
Hello Damien, broadcasting can solve your problem (see http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html): (A[np.newaxis,:]**B[:,np.newaxis]).sum(axis=0) gives the result you want. (assuming "import numpy as np", which is considered as a better practice as "from numpy import *") Ch

Re: [Numpy-discussion] combinatorial operations on a pair of arrays

2009-11-18 Thread Damien Moore
ugh... I goofed. The code snippet should have read 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]=(A[i]**B).sum(0) print C On Wed, Nov 18, 2009 at 2:17 PM, Damien Moore wrote: > The title of this e-mail is probably mislead

[Numpy-discussion] combinatorial operations on a pair of arrays

2009-11-18 Thread Damien Moore
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