Group Abstract Group Abstract

Message Boards Message Boards

0
|
6.1K Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Accumulate slow with units.

POSTED BY: Sander Huisman
3 Replies
Posted 10 years ago

I don't know hidden option for Accumulate. But you can also speed up calculations even more using data[[;;,1]] instead of QuantityMagnitude. You can use this if you know that all data points are in the same unit.

Quantity[Accumulate[data[[;; , 1]]], "Meters"]; // AbsoluteTiming
{0.000800182, Null}
POSTED BY: Alexey Golyshev
Posted 10 years ago

From Documentation:

Accumulate[list] is effectively equivalent to Rest[FoldList[Plus,0,list]]

data = Quantity[RandomReal[1, {500}], "Meters"];

Rest@FoldList[Plus, 0, data]; // AbsoluteTiming
{0.0273921, Null}
POSTED BY: Alexey Golyshev
POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard