Re: [Numpy-discussion] Sort performance with structured array

2013-04-07 Thread Charles R Harris
On Sun, Apr 7, 2013 at 5:56 PM, Charles R Harris wrote: > > > On Sun, Apr 7, 2013 at 5:23 PM, Tom Aldcroft < > aldcr...@head.cfa.harvard.edu> wrote: > >> I'm seeing about a factor of 50 difference in performance between >> sorting a random integer array versus sorting that same array viewed >> as

Re: [Numpy-discussion] Sort performance with structured array

2013-04-07 Thread Charles R Harris
On Sun, Apr 7, 2013 at 5:23 PM, Tom Aldcroft wrote: > I'm seeing about a factor of 50 difference in performance between > sorting a random integer array versus sorting that same array viewed > as a structured array. Am I doing anything wrong here? > > In [2]: x = np.random.randint(1, size=100

[Numpy-discussion] Sort performance with structured array

2013-04-07 Thread Tom Aldcroft
I'm seeing about a factor of 50 difference in performance between sorting a random integer array versus sorting that same array viewed as a structured array. Am I doing anything wrong here? In [2]: x = np.random.randint(1, size=1) In [3]: xarr = x.view(dtype=[('a', np.int)]) In [4]: tim

Re: [Numpy-discussion] sort descending with NaNs

2011-01-27 Thread Charles R Harris
On Thu, Jan 27, 2011 at 10:10 AM, Charles R Harris < charlesr.har...@gmail.com> wrote: > > > On Thu, Jan 27, 2011 at 9:50 AM, Fabrizio Pollastri > wrote: > >> Hello, >> >> when one has to find a given number of highest values in an array >> containing >> NaNs, the sort function (always ascending)

Re: [Numpy-discussion] sort descending with NaNs

2011-01-27 Thread Charles R Harris
On Thu, Jan 27, 2011 at 9:50 AM, Fabrizio Pollastri wrote: > Hello, > > when one has to find a given number of highest values in an array > containing > NaNs, the sort function (always ascending) is uncomfortable. > > Since numpy >= 1.4.0 NaNs are sorted to the end, so the searched values are > ju

[Numpy-discussion] sort descending with NaNs

2011-01-27 Thread Fabrizio Pollastri
Hello, when one has to find a given number of highest values in an array containing NaNs, the sort function (always ascending) is uncomfortable. Since numpy >= 1.4.0 NaNs are sorted to the end, so the searched values are just before the first NaN in a unpredictable position and one has to do anot

Re: [Numpy-discussion] sort documentation

2008-08-31 Thread Stéfan van der Walt
2008/8/31 Alan G Isaac <[EMAIL PROTECTED]>: > Thanks. So if I wish to determine the current > state of documentation, is the right place to go: > http://sd-2116.dedibox.fr/pydocweb/doc/ ? Jarrod, Could we set up a reverse proxy on doc.scipy.org to serve these pages (until we move the app over to

Re: [Numpy-discussion] sort documentation

2008-08-31 Thread Robert Kern
On Sun, Aug 31, 2008 at 09:33, dmitrey <[EMAIL PROTECTED]> wrote: > As for me I can't understand the general rule: when numpy funcs return > copy and when reference? It's driven by use cases and limitations of the particular functions. > For example why x.fill() returns None (do inplace modificat

Re: [Numpy-discussion] sort documentation

2008-08-31 Thread Alan G Isaac
Thanks. So if I wish to determine the current state of documentation, is the right place to go: http://sd-2116.dedibox.fr/pydocweb/doc/ ? Alan ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy

Re: [Numpy-discussion] sort documentation

2008-08-31 Thread Pauli Virtanen
Sun, 31 Aug 2008 10:27:59 -0700, Robert Kern wrote: > On Sun, Aug 31, 2008 at 09:26, Alan G Isaac <[EMAIL PROTECTED]> wrote: >> I find this confusing: >> >> numpy.sort(a, axis=-1, kind='quicksort', order=None) >> >> Return copy of 'a' sorted along the given axis. >> >> Perform an inpla

Re: [Numpy-discussion] sort documentation

2008-08-31 Thread Robert Kern
On Sun, Aug 31, 2008 at 09:26, Alan G Isaac <[EMAIL PROTECTED]> wrote: > I find this confusing: > > numpy.sort(a, axis=-1, kind='quicksort', order=None) > > Return copy of 'a' sorted along the given axis. > > Perform an inplace sort along the given axis using the algorithm > specifi

Re: [Numpy-discussion] sort documentation

2008-08-31 Thread dmitrey
As for me I can't understand the general rule: when numpy funcs return copy and when reference? For example why x.fill() returns None (do inplace modification) while x.ravel(), x.flatten() returns copy? Why the latters don't do inplace modification, as should be expected? D. Alan G Isaac wrot

[Numpy-discussion] sort documentation

2008-08-31 Thread Alan G Isaac
I find this confusing: numpy.sort(a, axis=-1, kind='quicksort', order=None) Return copy of 'a' sorted along the given axis. Perform an inplace sort along the given axis using the algorithm specified by the kind keyword. I suppose the last bit is supposed to refer to the ``so

Re: [Numpy-discussion] sort

2008-04-17 Thread Gael Varoquaux
On Thu, Apr 17, 2008 at 03:18:45AM -0700, wilson wrote: > i have a 1 dimensional array of floats that i want to sort in > descending order.i did as follows > from numpy import tolist,array,sort > y=array([..]) #may be 1000 items > z=sort(y) > l=z.tolist() > l.reverse() > rl=array(l) > now rl

Re: [Numpy-discussion] sort

2008-04-17 Thread Robert Kern
On Thu, Apr 17, 2008 at 5:18 AM, wilson <[EMAIL PROTECTED]> wrote: > i have a 1 dimensional array of floats that i want to sort in > descending order.i did as follows > > from numpy import tolist,array,sort > y=array([..]) #may be 1000 items > z=sort(y) > l=z.tolist() > l.reverse() > rl=

[Numpy-discussion] sort

2008-04-17 Thread wilson
i have a 1 dimensional array of floats that i want to sort in descending order.i did as follows from numpy import tolist,array,sort y=array([..]) #may be 1000 items z=sort(y) l=z.tolist() l.reverse() rl=array(l) now rl is a 1 dim array sorted in descending order. but i am looking for a better

Re: [Numpy-discussion] sort method raises unexpected error with axis=None

2008-02-13 Thread Charles R Harris
On Feb 13, 2008 1:52 PM, Matthew Brett <[EMAIL PROTECTED]> wrote: > Ah, > > To answer my own question: > > > Suggestion 1: > > Wrap the .sort method call in a tiny python wrapper of the form: > > > > def sort(self, axis=-1, kind='quicksort', order=None): > > if axis=None: > >_c_sort(se

Re: [Numpy-discussion] sort method raises unexpected error with axis=None

2008-02-13 Thread Matthew Brett
Ah, To answer my own question: > Suggestion 1: > Wrap the .sort method call in a tiny python wrapper of the form: > > def sort(self, axis=-1, kind='quicksort', order=None): > if axis=None: >_c_sort(self.ravel(), axis, kind, order) >else: > _c_sort(self, axis, kind, order) I

Re: [Numpy-discussion] sort method raises unexpected error with axis=None

2008-02-13 Thread Matthew Brett
Hi, > Is it possible, in fact, to do an inplace sort on an array with > axis=None (ie flat sort)? > > Should the sort method have its docstring changed to reflect the fact > that axis=None is not valid? Sorry to press on, but it would be good to resolve this somehow. Is there some reason not to:

Re: [Numpy-discussion] sort method raises unexpected error with axis=None

2008-02-12 Thread Anne Archibald
On 12/02/2008, Anne Archibald <[EMAIL PROTECTED]> wrote: > An efficient way to handle in-place (or out-of-place, come to think of > it) median along multiple axes is actually to take medians along all > axes in succession. That saves you some sorting effort, and some > programming effort, and doesn

Re: [Numpy-discussion] sort method raises unexpected error with axis=None

2008-02-12 Thread Anne Archibald
On 12/02/2008, Matthew Brett <[EMAIL PROTECTED]> wrote: > Is it possible, in fact, to do an inplace sort on an array with > axis=None (ie flat sort)? It is, sometimes; just make an array object to point to the flattened version and sort that: In [16]: b = a[:] In [17]: b.shape = (16,) In [18]:

Re: [Numpy-discussion] sort method raises unexpected error with axis=None

2008-02-12 Thread Matthew Brett
Hi, To rephrase: Is it possible, in fact, to do an inplace sort on an array with axis=None (ie flat sort)? Should the sort method have its docstring changed to reflect the fact that axis=None is not valid? Matthew On Feb 10, 2008 7:50 PM, Matthew Brett <[EMAIL PROTECTED]> wrote: > Hi, > > I ju

[Numpy-discussion] sort method raises unexpected error with axis=None

2008-02-10 Thread Matthew Brett
Hi, I just noticed this: >From the sort method docstring: axis : integer Axis to be sorted along. None indicates that the flattened array should be used. Default is -1. In [40]: import numpy as N In [41]: a = N.arange(10) In [42]: N.sort(a, None) Out[42]: array([0, 1, 2, 3

Re: [Numpy-discussion] sort bug

2007-05-02 Thread Nils Wagner
mark wrote: > Sorry for joining this discussion late. > If you are only interested in the four largest eigenvalues, there are > more efficient algorithms out there than just eig(). > There are algorithms that just give you the N largest. > Then again, I don't know of any Python implementations, but

Re: [Numpy-discussion] sort bug

2007-05-02 Thread mark
Sorry for joining this discussion late. If you are only interested in the four largest eigenvalues, there are more efficient algorithms out there than just eig(). There are algorithms that just give you the N largest. Then again, I don't know of any Python implementations, but I haven't looked, Mar

Re: [Numpy-discussion] sort bug

2007-04-29 Thread Matthieu Brucher
2007/4/29, Anton Sherwood <[EMAIL PROTECTED]>: > Anton Sherwood wrote: > > I'm using eigenvectors of a graph's adjacency matrix as "topological" > > coordinates of the graph's vertices as embedded in 3space (something I > > learned about just recently). Whenever I've done this with a graph that

Re: [Numpy-discussion] sort bug

2007-04-29 Thread Anton Sherwood
> Anton Sherwood wrote: > > I'm using eigenvectors of a graph's adjacency matrix as "topological" > > coordinates of the graph's vertices as embedded in 3space (something I > > learned about just recently). Whenever I've done this with a graph that > > *does* have a good 3d embedding, using the fi

Re: [Numpy-discussion] sort bug

2007-04-29 Thread Charles R Harris
On 4/29/07, Anton Sherwood <[EMAIL PROTECTED]> wrote: > Anton Sherwood wrote: > I refined it slightly: > > val,vec = numpy.linalg.eig(adj) > indx = val.argsort()[-4:-1] > val = val.take(indx) > vec = vec.take(indx, axis=1) > master = zip(val, vec.T) Charles R Harris wrot

Re: [Numpy-discussion] sort bug

2007-04-29 Thread Robert Kern
Anton Sherwood wrote: >> Anton Sherwood wrote: >> I refined it slightly: >> >> val,vec = numpy.linalg.eig(adj) >> indx = val.argsort()[-4:-1] >> val = val.take(indx) >> vec = vec.take(indx, axis=1) >> master = zip(val, vec.T) > > Charles R Harris wrote: >> But that won't ge

Re: [Numpy-discussion] sort bug

2007-04-29 Thread Anton Sherwood
> Anton Sherwood wrote: > I refined it slightly: > > val,vec = numpy.linalg.eig(adj) > indx = val.argsort()[-4:-1] > val = val.take(indx) > vec = vec.take(indx, axis=1) > master = zip(val, vec.T) Charles R Harris wrote: > But that won't get the 4 largest, and will ignore

Re: [Numpy-discussion] sort bug

2007-04-28 Thread Charles R Harris
On 4/28/07, Anton Sherwood <[EMAIL PROTECTED]> wrote: Travis Oliphant wrote: > One approach is to use argsort to create an index list of sorted > eigenvalues and then sort the eig and eigvector arrays before zipping > them together in a list of tuples. > > eig, val = numpy.linalg.eig(a) > > indx

Re: [Numpy-discussion] sort bug

2007-04-28 Thread Anton Sherwood
Travis Oliphant wrote: > One approach is to use argsort to create an index list of sorted > eigenvalues and then sort the eig and eigvector arrays before zipping > them together in a list of tuples. > > eig, val = numpy.linalg.eig(a) > > indx = eig.argsort() > eig = eig.take(indx) > val = val.t

Re: [Numpy-discussion] sort bug

2007-04-26 Thread tan2
Just doing argsort() on the whole array is faster (up until about 1e6 elements) because it does everything in C whereas heapq will create a lot of Python objects because it is treating the array as a general Python container. That's a good point. I wasn't thinking about the efficiency issue. _

Re: [Numpy-discussion] sort bug

2007-04-26 Thread Robert Kern
tan2 wrote: > > On 4/26/07, * Anton Sherwood* <[EMAIL PROTECTED] > > wrote: > > All I really need is the four highest eigenvalues and their > vectors. > I'll have a look in "Python Cookbook" to see if there's a more > efficient way

Re: [Numpy-discussion] sort bug

2007-04-26 Thread tan2
On 4/26/07, Anton Sherwood <[EMAIL PROTECTED]> wrote: > > > All I really need is the four highest eigenvalues and their vectors. > I'll have a look in "Python Cookbook" to see if there's a more > efficient way to do that partial sort. Maybe "heapq.nlargest()" is what you want? http://www.pyt

Re: [Numpy-discussion] sort bug

2007-04-26 Thread Anne Archibald
On 26/04/07, Anton Sherwood <[EMAIL PROTECTED]> wrote: > All I really need is the four highest eigenvalues and their vectors. It's not really very efficient, but sorting time is going to be tiny compared to however you get your eigenvalues, so you could argsort the eigenvalue array and use the re

Re: [Numpy-discussion] sort bug

2007-04-26 Thread Charles R Harris
On 4/26/07, Anton Sherwood <[EMAIL PROTECTED]> wrote: Travis Oliphant wrote: > cmp(x,y) must return -1, 0, or 1 which doesn't work on arrays with more > than 1 element because it is ambiguous. Thus you get this error. Ah. Since lists *can* be compared, I assumed arrays would inherit that prop

Re: [Numpy-discussion] sort bug

2007-04-26 Thread Travis Oliphant
Anton Sherwood wrote: > Travis Oliphant wrote: > >> cmp(x,y) must return -1, 0, or 1 which doesn't work on arrays with more >> than 1 element because it is ambiguous. Thus you get this error. >> > > Ah. Since lists *can* be compared, I assumed arrays would inherit > that property. > >

Re: [Numpy-discussion] sort bug

2007-04-26 Thread Anton Sherwood
Travis Oliphant wrote: > cmp(x,y) must return -1, 0, or 1 which doesn't work on arrays with more > than 1 element because it is ambiguous. Thus you get this error. Ah. Since lists *can* be compared, I assumed arrays would inherit that property. > The operation is undefined. What do you actuall

Re: [Numpy-discussion] sort bug

2007-04-26 Thread Travis Oliphant
Anton Sherwood wrote: > This code -- > > adj = [ [eval(y) for y in x.split()] for x in infile ] > val,vec = numpy.linalg.eig(adj) > master = zip( val, vec.transpose() ) > master.sort() > > *sometimes* gives this error: > > Traceback (most recent call last): > F

[Numpy-discussion] sort bug

2007-04-25 Thread Anton Sherwood
This code -- adj = [ [eval(y) for y in x.split()] for x in infile ] val,vec = numpy.linalg.eig(adj) master = zip( val, vec.transpose() ) master.sort() *sometimes* gives this error: Traceback (most recent call last): File "3work.py", line 14, in