Shuffle a numpy array

前端 未结 3 1424
一向
一向 2021-01-11 09:31

I have a 2-d numpy array that I would like to shuffle. Is the best way to reshape it to 1-d, shuffle and reshape again to 2-d or is it possible to shuffle without reshaping?

3条回答
  •  渐次进展
    2021-01-11 10:04

    You could shuffle a.flat:

    >>> np.random.shuffle(a.flat)
    >>> a
    array([[6, 1, 2],
           [3, 5, 0],
           [7, 8, 4]])
    

提交回复
热议问题