MathGroup Archive 1999

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

Search the Archive

Re: Counting list elements above/below a given value

  • To: mathgroup at smc.vnet.net
  • Subject: [mg17281] Re: [mg17202] Counting list elements above/below a given value
  • From: "Andrzej Kozlowski" <andrzej at tuins.ac.jp>
  • Date: Fri, 30 Apr 1999 23:22:20 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

There are two problems here. First, your usage of patterns in Count is 
wrong. Here is how it works. Lets create a pretty big matrix:

In[1]:=
m=Array[Random[Integer,{1,100}]&,{200,200}];
Now

In[2]:=
Count[m,x_/;x>20,Infinity]//Timing
Out[2]=
{1.08333 Second, 32059}

That seems to be fast enough for me (on PowerBook G3, 233 mghz).

The second problem is that your original method is actually slightly faster:

In[3]:=
Length[Select[Flatten[m], 20< #1&]]//Timing
Out[3]=
{0.983333 Second, 32059}

So now my question: what do you consider slow in this case?
--
Andrzej Kozlowski
Toyama International University
JAPAN
http://sigma.tuins.ac.jp
http://eri2.tuins.ac.jp


----------
>From: "W.W. Sampson" <w.sampson at umist.ac.uk>
To: mathgroup at smc.vnet.net
>To: mathgroup at smc.vnet.net
>Subject: [mg17281] [mg17202] Counting list elements above/below a given value
>Date: Mon, Apr 26, 1999, 2:20 PM
>

> 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


  • Prev by Date: Re: 3d Custom Color Output
  • Next by Date: Books on the front end
  • Previous by thread: Re: Counting list elements above/below a given value
  • Next by thread: Re: Counting list elements above/below a given value