[Numpy-discussion] fast method to to count a particular value in a large matrix
Jerome Kieffer
Jerome.Kieffer@esrf...
Sat Feb 4 14:42:48 CST 2012
On Sat, 4 Feb 2012 14:35:08 -0600
Benjamin Root <ben.root@ou.edu> wrote:
>
> no.unique() can return indices and reverse indices. It would be trivial to
> histogram the reverse indices using np.histogram().
Even np.histogram(abc,unique_elem) or something like this.
Works if unique_elem is ordered.
np.histogram(abc,list(unique_elem)+[unique_elem[-1]+1])[0].reshape(-1,1)
is 40x faster and gives the same result.
--
Jérôme Kieffer
Data analysis unit - ESRF
More information about the NumPy-Discussion
mailing list