MathGroup Archive 2006

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

Search the Archive

Re: Count Function


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}


  • Prev by Date: Mathematica for Mathematics Education
  • Next by Date: Re: Re: Count Function
  • Previous by thread: Re: Count Function
  • Next by thread: Filtering Strings