Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #5474
| From | Heike Gramberg <heike.gramberg@gmail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: average of the consecutive coin tosses |
| Date | 2011-10-07 08:51 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <j6meic$7c9$1@smc.vnet.net> (permalink) |
| References | <201110060818.EAA22381@smc.vnet.net> |
You could do something like
tr = With[{list = RandomInteger[{0, 1}, 10000]}, Accumulate[list]/Range[Length[list]]];
On my machine this is about a factor 2.5 faster than the original code.
Heike.
On 6 Oct 2011, at 10:18, michael partensky wrote:
> Hi.
>
> What are the better ways of doing what this guy does very inefficiently for
> the average of the consecutive coin tosses:
>
> tr = (flips = 1; (#/flips++) & /@ Accumulate[Table[toss, {1000}]]) // N);
>
> where
>
> toss= RandomInteger[];
>
> Thanks
> Michael
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: average of the consecutive coin tosses Heike Gramberg <heike.gramberg@gmail.com> - 2011-10-07 08:51 +0000
csiph-web