Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Calculate number of occurences in tha table' topicStudent Support Forum > General > Archives > "Calculate number of occurences in tha table"

< Previous CommentHelp | Reply To Comment | Reply To Topic
Author Comment/Response
yehuda
01/14/13 11:20am

In Response To 'Re: Calculate number of occurences in tha table'
---------
Count is good for counting patterns
For large matrices it is much more efficient to use Tally
here are the results for a 1000X1000 matrix
f[n_] := Count[Flatten[bigT], n]
bigT = RandomInteger[10, {1000, 1000}];
Timing[Table[{n,f[n]},{n,0,10}];]/Timing[Tally[Flatten@bigT];
(Timing[Table[{n, f[n]}, {n, 0, 10}];]/
Timing[Tally[Flatten@bigT];])[[1]]

resulting with a factor of more than 60 time faster. Part of it is the need to flatten the matrix for each new value. Modifying it for a single flattening reduces this to a factor of 58


so, for big data arrays / matrices and alike it is wiser to use Tally
Count is more flexible, but less efficient

yehuda



URL: ,

Subject (listing for 'Calculate number of occurences in tha table')
Author Date Posted
Calculate number of occurences in tha table ed 01/13/13 4:00pm
Re: Calculate number of occurences in tha table Bill Simpson 01/13/13 5:25pm
Re: Re: Calculate number of occurences in tha t... yehuda 01/14/13 11:20am
< Previous CommentHelp | Reply To Comment | Reply To Topic