b[a.argsort()]
should do the trick.
Here's how it works. First you need to find a permutation that sorts a. argsort
is a method that computes this:
>>> a = numpy.array([2, 3, 1])
>>> p = a.argsort()
>>> p
[2, 0, 1]
You can easily check that this is right:
>>> a[p]
array([1, 2, 3])
Now apply the same permutation to b.
>>> b = numpy.array([4, 6, 7])
>>> b[p]
array([7, 4, 6])
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…