numpy.random.shuffle#
- random.shuffle(x)#
就地修改序列,透過混洗其內容。
此函數僅沿多維陣列的第一軸混洗陣列。子陣列的順序會被更改,但其內容保持不變。
- 參數:
- xndarray 或 MutableSequence
要混洗的陣列、列表或可變序列。
- 返回:
- None
參見
random.Generator.shuffle
新程式碼應使用的方法。
範例
>>> arr = np.arange(10) >>> np.random.shuffle(arr) >>> arr [1 7 5 2 9 4 3 6 0 8] # random
多維陣列僅沿第一軸混洗
>>> arr = np.arange(9).reshape((3, 3)) >>> np.random.shuffle(arr) >>> arr array([[3, 4, 5], # random [6, 7, 8], [0, 1, 2]])