[Chimera-users] Sum of volume data values
Thomas Goddard
goddard at cgl.ucsf.edu
Thu Apr 13 10:06:08 PDT 2006
Hi Eran,
The m.flat only works for "contiguous arrays". Contiguous means you
the values are all layed out in memory in order with no gaps. You get a
non-contiguous array if you take an array subblock m2 = m[50:100,:,:], or
if you change the step size m2 = m[::2,:,:], or if you permute the order
of the axes m2 = Numeric.transpose(m). The only case you can get from
the MRC_Data.matrix() call is the permuting of axes. The MRC format
supports permutations of data axes, so depending on your file the
m.flat will fail.
The solution is to use
import Numeric
m1d = Numeric.ravel(m)
sum = Numeric.sum(m1d)
instead of
import Numeric
sum = Numeric.sum(m.flat)
The Numeric.ravel() call makes a 1D array, making a copy if the passed in
array is non-contiguous. This will certainly be much faster than your
nested for loops for large arrays.
Tom
More information about the Chimera-users
mailing list