[Numpy-discussion] Combination of element-wise and matrix multiplication

Jonno jonnojohnson@gmail....
Thu Jul 3 14:53:28 CDT 2008


I have two 2d arrays a & b for example:
a=array([c,d],[e,f])
b=array([g,h],[i,j])
Each of the elements of a & b are actually 1d arrays of length N so I
guess technically a & b have shape (2,2,N).
However I want to matrix multiply a & b to create a 2d array x, where
the elements of x are created with element-wise math as so:
x[0,0] = c*g+d*i
x[0,1] = c*h+d*j
x[1,0] = e*g+f*i
x[1,1] = e*h+f*j

What is the simplest way to do this? I ended up doing the matrix
multiplication of a & b manually as above but this doesn't scale very
nicely if a & b become larger in size.

Cheers,

Jonno.

-- 
"If a theory can't produce hypotheses, can't be tested, can't be
disproven, and can't make predictions, then it's not a theory and
certainly not science." by spisska  on Slashdot, Monday April 21, 2008


More information about the Numpy-discussion mailing list