4
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
2
  • 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. Commented Feb 26, 2011 at 18:22
  • sort the x array using the values in the y array Commented Feb 26, 2011 at 18:38

1 Answer 1

2

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]
Sign up to request clarification or add additional context in comments.

2 Comments

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...
Yeah you have to change the two last lines like senderle said but that's what I wanted thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.