Numpy shuffle multidimensional array by row only, keep column order unchanged

后端 未结 6 619
不思量自难忘°
不思量自难忘° 2020-12-05 12:52

How can I shuffle a multidimensional array by row only in Python (so do not shuffle the columns).

I am looking for the most efficient solution, because my ma

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-05 13:26

    You can shuffle a two dimensional array A by row using the np.vectorize() function:

    shuffle = np.vectorize(np.random.permutation, signature='(n)->(n)')
    
    A_shuffled = shuffle(A)
    

提交回复
热议问题