Re: Counting number of numbers in a large list between two valus
- To: mathgroup at smc.vnet.net
- Subject: [mg114518] Re: Counting number of numbers in a large list between two valus
- From: Andy <andyr at wolfram.com>
- Date: Mon, 6 Dec 2010 06:13:59 -0500 (EST)
On 12/5/2010 8:57 PM, Lyle wrote: > tallydata[{x1_, x2_}] := Length[Select[data, x1<= #<= x2&]] UnitStep can be quite fast and saves you from having to sort. In[12]:= data = RandomVariate[NormalDistribution[], 20000000]; tallydata2[data_, {x1_, x2_}] := Total[UnitStep[data - x1]*UnitStep[x2 - data]] tallydata[data_, {x1_, x2_}] := Length[Select[data, x1 <= # <= x2 &]] tallydata2[data, {2, 3}] // AbsoluteTiming Out[14]= {1.4374356, 426159} tallydata[data, {2, 3}] // AbsoluteTiming Out[15]= {18.2491824, 426159} Andy Ross Wolfram Research