On Sun, Feb 16, 2014 at 6:15 PM, <josef.p...@gmail.com> wrote: > On Sun, Feb 16, 2014 at 5:50 PM, Eelco Hoogendoorn > <hoogendoorn.ee...@gmail.com> wrote: >> >> My guess; >> >> First of all, you are actually manipulating twice as much data as opposed to >> an inplace sort. >> >> Moreover, an inplace sort gains locality as it is being sorted, whereas the >> argsort is continuously making completely random memory accesses. >> >> >> -----Original Message----- >> From: josef.p...@gmail.com >> Sent: Sunday, February 16, 2014 11:43 PM >> To: Discussion of Numerical Python >> Subject: [Numpy-discussion] argsort speed >> >> currently using numpy 1.6.1 >> >> What's the fastest argsort for a 1d array with around 28 Million >> elements, roughly uniformly distributed, random order? >> >> Is there a reason that np.argsort is almost 3 times slower than np.sort? >> >> I'm doing semi-systematic timing for a stats(models) algorithm. > > I was using np.sort, inplace sort is only a little bit faster > > It looks like sorting first, and then argsorting is faster than argsort alon > > pvals.sort() > sortind = np.argsort(pvals)
Ok, that was useless, that won't be anything I want. Josef > > replacing the inplace sort in the above reduces speed only a bit > > -------------- > import time > use_master = True > if use_master: > import sys > sys.path.insert(0, > r"E:\Josef\!reps\numpy\dist\Programs\Python27\Lib\site-packages") > > import numpy as np > print "np.__version__ =", np.__version__ > > n = 5300 > pvals = np.random.rand(n**2) > > t0 = time.time() > > p = np.sort(pvals) > t1 = time.time() > > sortind = np.argsort(pvals) > t2 = time.time() > > pvals.sort() > sortind = np.argsort(pvals) > t3 = time.time() > > print t1 - t0, t2 - t1, t3 - t2 > print (t2 - t1) * 1. / (t1 - t0), (t3 - t2) * 1. / (t1 - t0) > ------------ > > np.__version__ = 1.9.0.dev-2868dc4 > 3.91900014877 9.5569999218 4.92900013924 > 2.43863219163 1.2577187936 > > Josef > > >> >> Josef >> _______________________________________________ >> NumPy-Discussion mailing list >> NumPy-Discussion@scipy.org >> http://mail.scipy.org/mailman/listinfo/numpy-discussion >> >> _______________________________________________ >> NumPy-Discussion mailing list >> NumPy-Discussion@scipy.org >> http://mail.scipy.org/mailman/listinfo/numpy-discussion _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion