Reputation: 999
I have this numpy array a = [1, 2, 3, 4, 5; 6, 7, 8, 9, 10; 11, 12, 13, 14, 15 ]
and a list of numbers [0, 2, 1]. I want to shuffle a
's rows according to the list of numbers in a way that a = [1, 2, 3, 4, 5; 11, 12, 13, 14, 15; 5, 6, 7, 8, 9]
. Is there a way to do it without creating a new numpy array for the result?
Upvotes: 0
Views: 76
Reputation: 1404
import numpy as np
a = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15]])
a[:] = a[[0,2,1]]
Upvotes: 3