MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Counting number of numbers in a large list between two valus

  • To: mathgroup at smc.vnet.net
  • Subject: [mg114540] Re: Counting number of numbers in a large list between two valus
  • From: "Kevin J. McCann" <Kevin.McCann at umbc.edu>
  • Date: Tue, 7 Dec 2010 06:46:05 -0500 (EST)
  • References: <idigjf$ist$1@smc.vnet.net>

This is the fastest I got as well.

Kevin

P.S. I never knew about Clip or Unitize before. Thanks.

On 12/6/2010 6:14 AM, Fred Simons wrote:
> Op 6-12-2010 3:57, Lyle schreef:
>> Dear Listers,
>>
>> I have a large (5-20million) one dimensional list of real numbers and
>> I want to count the number of entries in the list that lie between 2
>> specific values (x1, x2). I need to run the function for a number of
>> different ranges.
>>
>> ie. number of list entries (l), where x1<= l<= x2
>>
> This seems to be a pretty fast solution:
>
> In[28]:= between[lst_, {x1_, x2_}] :=
>    Total[Unitize[Clip[lst, {x1, x2}, {0, 0}]]]
>
> In[29]:= lst = RandomReal[{-100, 100}, {10^7}];
> between[lst, {-50, -40}] // Timing
>
> Out[30]= {0.125, 500249}
>
> Regards,
>
> Fred Simons
> Eindhoven University of Technology
>
>


  • Prev by Date: Re: Changing Graph style
  • Next by Date: JLink on virtual Linux server: Cannot createKernelLink
  • Previous by thread: Re: Counting number of numbers in a large list between two valus
  • Next by thread: Re: Counting number of numbers in a large list between two valus