I have a NxM matrix called coefficients that I want to sort:
import numpy
N = 10
M = 42
coefficients = numpy.random.uniform(size=(N, M))
I have an array called order with N elements that says the order that the rows of coefficients should be in:
order = numpy.random.choice(range(N), N, False)
I'm sorting coefficients by sorting order:
coefficients = numpy.array([mag for (orig, mag)
in sorted(zip(order, coefficients),
key=lambda pair: pair[0])])
This works, but it's probably slower than it should be. If this was in 1D, I'd use fromiter, but I don't know how to tackle this since it's 2D. Is there an optimization I can make here?