Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Speedup np.unique

I am looking to speed up the following piece of code:

NNlist=[np.unique(i) for i in NNlist] 

where NNlist is a list of np.arrays with duplicated entries.

Thanks :)

like image 568
bios Avatar asked Dec 03 '12 17:12

bios


1 Answers

numpy.unique is already pretty optimized, you're not likely to get get much of a speedup over what you already have unless you know something else about the underlying data. For example if the data is all small integers you might be able to use numpy.bincount or if the unique values in each of the arrays are mostly the same there might be some optimization that could be done over the whole list of arrays.

like image 182
Bi Rico Avatar answered Sep 30 '22 13:09

Bi Rico