[SciPy-user] Arrays and sorting methods

Alan G Isaac aisaac at american.edu
Tue Feb 8 11:06:10 EST 2005


On Tue, 08 Feb 2005, Manuel de Ferran apparently wrote:
> I was surprised that I could not find any sorting array based on the
> columns, that might be usefull with itemfreq(), for instance.


This is from http://www.american.edu/econ/pytrix/pyGAUSS.py

hth,
Alan Isaac

#sortc:   sort array on specified column NUMBER
#         NOT (!!) on column *index* (=colNUM-1)'''
# Format:    y = sortc(x,colNUM)
# Input:     x        RxC array
#            colNUM   integer 
# Output:    y        RxC array
# Remarks:   sorts on column *NUMBER* 
#            (starting at 1, following GAUSS convention)
#	    NOT (!!) on column *index* (=colNUM-1)
# Date:      5 Aug 2004
def sortc(x,colNUM):
	if not colNUM in range(1,1+shape(x)[1]):
        	raise ValueError, 'Index out of range.'
	return take(x,argsort(asarray(x)[:,colNUM-1],0))






More information about the SciPy-User mailing list