I'm looking for a one line solution that would help me do the following.
Suppose I have
array = np.array([10, 20, 30, 40, 50])
I'd like to rearrange it based upon an input ordering. If there were a numpy function called arrange
, it would do the following:
newarray = np.arrange(array, [1, 0, 3, 4, 2])
print newarray
[20, 10, 40, 50, 30]
Formally, if the array to be reordered is m x n, and the "index" array is 1 x n, the ordering would be determined by the array called "index".
Does numpy have a function like this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…