 
 
 
 
 
 
Re: Count Function
- To: mathgroup at smc.vnet.net
- Subject: [mg65556] Re: Count Function
- From: "Ray Koopman" <koopman at sfu.ca>
- Date: Fri, 7 Apr 2006 06:14:37 -0400 (EDT)
- References: <e1091t$ljd$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Gregory Lypny wrote:
> The syntax will be the death of me.
>
> Count[X[[All,14]], -9.] will tally how many elements in column 14 of
> matrix X are equal to -9, but I can't for the life of me figure out
> how to get how many are greater than -9.  Any hint would be most
> appreciated.
>
> 	Greg
My earlier post omitted the really fast one.
In[1]:= x = Table[Random[Integer,99],{1*^6}];
        Timing@Count[x, x_/;x>14]
        Timing@Length@Select[x,#>14&]
        Timing[SparseArray[Boole@Positive[x-14]] /.
               SparseArray[_, _, _, p_] :> Length@p[[2, 2]]]
        Timing[SparseArray[UnitStep[x-15]] /.
               SparseArray[_, _, _, p_] :> Length@p[[2, 2]]]
Out[2]= {2.17 Second,850268}
Out[3]= {2.17 Second,850268}
Out[4]= {1.1 Second,850268}
Out[5]= {0.09 Second,850268}

