>>> A = np.random.randint(5, size=(10,3))>>> Aarray([[1, 3, 0], [3, 2, 0], [0, 2, 1], [1, 1, 4], [3, 2, 2], [0, 1, 0], [1, 3, 1], [0, 4, 1], [2, 4, 2], [3, 3, 1]])>>> idx = np.random.randint(10, size=2)>>> idxarray([7, 6])>>> A[idx,:]array([[0, 4, 1], [1, 3, 1]])
一般情况下将其放在一起:
A[np.random.randint(A.shape[0], size=2), :]
对于非替换(numpy 1.7.0+):
A[np.random.choice(A.shape[0], 2, replace=False), :]
我不认为有一种很好的方法可以在不替换1.7之前生成随机列表。也许您可以设置一个小的定义,以确保两个值不相同。



