Re: Counting list elements above/below a given value
- To: mathgroup at smc.vnet.net
- Subject: [mg17271] Re: Counting list elements above/below a given value
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Fri, 30 Apr 1999 02:34:50 -0400
- References: <7g0qv1$drj@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Bill Count needs a pattern; and in this case a level specification. But pattern matching is slower than the flattening and testing (with Select) that you have used. Here are some timings. data= Table[Random[],{280},{280}]; Count[data, _?(#>.5&),{2}]//Timing {6.86 Second,39219} Count[data, x_/;x>.5,{2}]//Timing {6.26 Second,39219} Length[Select[Flatten[data], #1>.5&]]//Timing {5.82 Second,39219} Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay at haystack.demon.co.uk Voice: +44 (0)116 271 4198 Fax: +44 (0)870 164 0565 W.W. Sampson <w.sampson at umist.ac.uk> wrote in message news:7g0qv1$drj at smc.vnet.net... > I wish to count the number of elements within a list above > a given value. I can do this using the following: > > Length[Select[Flatten[listname], value > #1&]] > > However, my list is a 280 x 280 matrix and consequently > this takes a while to evaluate. My guess is that there > must be something more efficient. I've tried: > > Count[listname, value > #1&] > > but the output given is 0, which I know to be incorrect. > > Any ideas appreciated. > > Bill >