Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Consider that I load columns from a text file using:

x, y, z = np.loadtxt(myfile, unpack=True)

What would be the syntax to sort x, y and z by increasing values of x ?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You want to use numpy.argsort

argsortx = np.argsort(x)
x, y, z = x[argsortx], y[argsortx], z[argsortx]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.