cumulative sum in SAGE

74 views
Skip to first unread message

Funmilayo Eniola Kazeem

unread,
Apr 16, 2014, 4:12:15 AM4/16/14
to sage-s...@googlegroups.com
Hello,

Is there a command for cumulative sum in SAGE? If yes, what is it? If not, how do I do it?

Thanks,

John Cremona

unread,
Apr 16, 2014, 5:07:50 AM4/16/14
to SAGE support
What do you mean by cumulative sum? There is sum (from python), e.g.

sage: sum(range(100))
4950
sage: sum([i^3 for i in range(100)])
24502500

John Cremona
> --
> You received this message because you are subscribed to the Google Groups
> "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-support...@googlegroups.com.
> To post to this group, send email to sage-s...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sage-support.
> For more options, visit https://groups.google.com/d/optout.

Jori Mantysalo

unread,
Apr 16, 2014, 5:33:38 AM4/16/14
to sage-s...@googlegroups.com
On Wed, 16 Apr 2014, Funmilayo Eniola Kazeem wrote:

> Is there a command for cumulative sum in SAGE? If yes, what is it? If not,
> how do I do it?

somenumbers=[1, 1.4142, 1.7321, 2]
[sum(somenumbers[0:i]) for i in range(1, len(somenumbers)+1)]

Of course not optimal, but easy if speed is not an issue. I don't know if
this if fast with %cython or not.

--
Jori Mäntysalo

William Stein

unread,
Apr 16, 2014, 7:04:04 AM4/16/14
to sage-support support

stats.TimeSeries has a very fast sums method - everything must be float though.  Numpy also has something.

--
You received this message because you are subscribed to the Google Groups "sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages