[Numpy-discussion] Suppressing "nesting" (recursion, descent) in array construction.
Michael McNeil Forbes
mforbes at physics.ubc.ca
Wed Jun 20 04:38:56 EDT 2007
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
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.
More information about the NumPy-Discussion