I have an array y and a matrix X that is CSR sparse.
I need to do a random sort of y and X where each row of y corresponds to a row in X.
Using NumPy, how do I do that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In order to get a random sort, you could try to use the
np.random.shufflefunction.You can now use
indicesto randomizeywith fancy indexingy_new = y[indices].You could use the same
indicesto reorder your matrix, but be careful, CSR matrices don’t support fancy indexing. You’ll have to transform it to LIL, reorder it, then retransform it to CSR.