[SciPy-user] Sort by first n columns in an array

Neil Crighton neilcrighton@gmail....
Fri Jul 10 06:26:20 CDT 2009

Dharhas Pothina <Dharhas.Pothina <at> twdb.state.tx.us> writes:

> >>> Neil Crighton <neilcrighton <at> gmail.com> 7/8/2009 6:14 PM >>>
> >Something like this should work:
> >
> >data = np.genfromtxt(filename, dtype=None, usecols=(0,1,2),
> >                    names='year,month,day')
> >data.sort(order=['year', 'month', 'day'])
> That works if I know the number of columns prior to reading the file. In this
case I'm reading a file with an
> unknown number of columns. I know that the first six columns are the date 

If you know the first six columns are the date fields, can't you use

data = np.genfromtxt(filename, dtype=None, usecols=(0,1,2,3,4,5),


That doesn't make any assumption about the number of columns (as long as 
there's at least six of them).


More information about the SciPy-user mailing list