[Numpy-discussion] sum of positive values in an array
Fri Sep 5 09:32:41 CDT 2008
> What are the relative merits of
> a[a > 0].sum()
> Second one is more OO, takes a few keystrokes less to type. Is there
> any real difference if it came to very large arrays? Or is it 'just' a
> style question?
In this case, it is style: sum(a) really calls a.sum() internally; in
the second case, you are sure to call numpy sum, and not python sum,
which is a common mistake of people new to numpy.
More information about the Numpy-discussion