[SciPy-user] summation of array elements

Horst Horstsen horstess2001 at yahoo.de
Wed Jun 30 13:41:53 CDT 2004


Hi Scipy-Experts,

I've got a question concerning the summation of elements in an array. The 
following small sample programm illustrates the problem:

_________________________________
from scipy.xplt import *
from RandomArray import *

nx,ny=100,10

def gen_lattice(nx,ny,c):
     x=uniform(0.0,1.0,((nx,ny)))
     return (x<c)

c=1
x=gen_lattice(nx,ny,c)
print sum(x)
print sum(ravel(x))
___________________________________

One would expect an output of ten 100s and a 1000 but instead of the 1000 
it prints 232. Does anybody have a idea whats wrong?

To anticipate corresponding questions, normally I also want to vary c 
between 0..1   ;-)

Thank you for your help!
Ciao by Philipp




More information about the SciPy-user mailing list