import numpy as np
x = np.array(range(10 * 30)).reshape(100, 3)
y = np.array(range(1010, 10, -10))
res = sorted(x, key = lambda y:y) #ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
res = sorted(x, key=y) #TypeError: 'tuple' object is not callable
-
What is your question/problem, and what are you trying to do? It would be nice to have some more description instead of just posting code.Karmastan– Karmastan2011-02-26 18:22:56 +00:00Commented Feb 26, 2011 at 18:22
-
sort the x array using the values in the y arraychimichanga– chimichanga2011-02-26 18:38:09 +00:00Commented Feb 26, 2011 at 18:38
Add a comment
|
1 Answer
Try argsort:
import numpy as np
x = np.array(range(10 * 30)).reshape(100, 3)
y = np.array(range(1010, 10, -10))
args = y.argsort(axis = 0)
print x[args]
2 Comments
senderle
This is cool -- but perhaps this should be
args = y.argsort() and print x[args]? At least that seems to be what the OP is asking for...chimichanga
Yeah you have to change the two last lines like senderle said but that's what I wanted thanks.