我有一个numpy数组。
[['5.1' '3.5' '1.4' '0.2' 'Iris-setosa']
['4.9' '3.0' '1.4' '0.2' 'Iris-setosa']
['5.6' '3.0' '4.5' '1.5' 'Iris-versicolor']
['5.8' '2.7' '4.1' '1.0' 'Iris-versicolor']
['6.2' '3.4' '5.4' '2.3' 'Iris-virginica']
['5.9' '3.0' '5.1' '1.8' 'Iris-virginica']]
如何对行进行随机播放?
我尝试了numpy.random.shuffle()
,但由于缺少逗号而返回None
答案 0 :(得分:2)
numpy.random.shuffle
旨在就地,这意味着它应该返回None
,而是修改您的数组。
import numpy as np
x = np.arange(9).reshape((3,3))
print(x)
# [[0 1 2]
# [3 4 5]
# [6 7 8]]
np.random.shuffle(x)
print(x)
# [[3 4 5]
# [0 1 2]
# [6 7 8]]