finding most common elements between thousands of multiple arrays.
neilcrighton at gmail.com
Sat Jul 4 15:39:41 CEST 2009
You can join all your arrays into a single big array with concatenate.
>>> import numpy as np
>>> a = np.concatenate(array_of_arrays)
Then count the number of occurrances of each unique element using this trick
with searchsorted. This should be pretty fast.
>>> unique_a = np.unique(a)
>>> count = 
>>> for val in unique_a:
... count.append(a.searchsorted(val,side='right') - a.searchsorted(val,
>>> mostcommonvals = unique_a[np.argsort(count)[-25:]]
More information about the Python-list