[SciPy-user] weave.inline question - passing an array of an array

Alan Jackson alan at ajackson.org
Sun Jan 13 21:40:45 EST 2008


I have a bit of weave.inline code I have been quite happy with, but
I now need to extend it. Essentially I need to replace a spot where
I multiply some elements of an array by elements of a matrix, with
a weighted sum of the same multiplies, where I can now have an arbitrary
number of vectors and corresponding matrices.

float Score = Matrix[s1[idx1]*NMatrix[1] + s2[idx2]];

becomes

float Score = 0.0
for (unsigned int alphaidx = 0; alphaidx <Nalpha[0]; ++alphaidx) {
    Score += alpha[alphaidx] * something
}

where now I have arr_s1 = array of s1 arrays,
                 arr_s2 = array of s2 arrays
and              arr_Matrix = array of Matrices

in python it would look like

Score = 0.0
for alphaidx in range(0, len(alpha)):
    Score += alpha[alphaidx]*arr_Matrix[alphaidx][arr_s1[alphaidx][idx1], arr_s2[alphaidx][idx2]] 

Trying to figure out if it is even possible to do this with inline, and if so,
how to actually write it...

-- 
-----------------------------------------------------------------------
| Alan K. Jackson            | To see a World in a Grain of Sand      |
| alan at ajackson.org          | And a Heaven in a Wild Flower,         |
| www.ajackson.org           | Hold Infinity in the palm of your hand |
| Houston, Texas             | And Eternity in an hour. - Blake       |
-----------------------------------------------------------------------



More information about the SciPy-User mailing list