Services & Resources / Wolfram Forums / MathGroup Archive
-----

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: [mg114523] Re: Counting number of numbers in a large list between two valus
  • From: Fred Simons <f.h.simons at tue.nl>
  • Date: Mon, 6 Dec 2010 06:14:54 -0500 (EST)

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: Counting number of numbers in a large list between two valus
  • Next by Date: Re-virginating Manipulates?
  • 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