[Numpy-discussion] Suppressing "nesting" (recursion, descent) in array construction.

Michael McNeil Forbes mforbes@physics.ubc...
Wed Jun 20 03:38:56 CDT 2007


Hi,

I have a list of tuples that I am using as keys and I would like to  
sort this along with some other arrays using argsort.  How can I do  
this?  I would like to do something like:

# These are constructed using lists because they accumulate using  
append()
data = [1.0, 3,0]
keys = [('a',1),('b',2)]

# Convert to arrays for indexing
data = array(data1)
keys = array(keys) # <--Converts to a 2d array rather than 1d array  
of tuples	.

inds = argsort(data)
data[:] = data[inds]
keys[:] = keys[inds]

It seems there should be some way of specifying to the array  
constructor not to 'descend' (perhaps by specifying the desired  
dimensions of the final array or something) but I cannot find a nice  
way around this.

Any suggestions?

Thanks,
Michael.



More information about the Numpy-discussion mailing list