Vincent
Vincent

Reputation: 60341

Sort single column numpy arrays using another numpy array in Python

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 ?

Upvotes: 0

Views: 129

Answers (1)

Francesco Montesano
Francesco Montesano

Reputation: 8658

You want to use numpy.argsort

argsortx = np.argsort(x)
x, y, z = x[argsortx], y[argsortx], z[argsortx]

Upvotes: 2

Related Questions