Timeline for Restricted accumulation of values
Current License: CC BY-SA 3.0
10 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 29, 2012 at 21:49 | comment | added | whuber |
@Rojo Here's a fix. Not only is it straightforward, it's fast: Block[{sums = Accumulate[data], k, i}, k = Position[sums, x_?Positive, 1, 1]; i = If[k == {}, 0, Part[k, 1, 1]]; Take[sums, i]~Join~Drop[data, i]] .
|
|
Nov 2, 2012 at 3:24 | comment | added | Rojo | Also I think this approach would only work for data whose accumulation doesn't go negative after getting positive for the first time, right? | |
Nov 2, 2012 at 3:23 | comment | added | Rojo | Oh, I didn't see you had mentioned it. 1-UnitStep[-#] would fix that, but it's less fast. He mentioned wanting >0 but actually programmed >=0 | |
Nov 2, 2012 at 3:00 | comment | added | rm -rf♦ |
@Rojo Yep, I mentioned it in my answer, but note that UnitStep is equivalent to ≥0 , whereas OP only mentioned >0 .
|
|
Nov 2, 2012 at 0:28 | comment | added | Rojo | UnitStep doesn't have that problem | |
Nov 1, 2012 at 23:03 | comment | added | rm -rf♦ | @SimonWoods Good point. Fixed now :) | |
Nov 1, 2012 at 23:03 | history | edited | rm -rf♦ | CC BY-SA 3.0 |
added 129 characters in body
|
Nov 1, 2012 at 22:46 | review | Low quality posts | |||
Nov 1, 2012 at 23:06 | |||||
Nov 1, 2012 at 22:33 | comment | added | Simon Woods |
HeavisideTheta[0] is undefined, so this has problems if the total reaches zero.
|
|
Nov 1, 2012 at 22:27 | history | answered | rm -rf♦ | CC BY-SA 3.0 |