>>> A = np.random.randint(5, size=(10,3)) >>> A array([[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) >>> idx array([7, 6]) >>> A[idx,:] array([[0, 4, 1], [1, 3, 1]])
Combining this for the general case:
A[np.random.randint(A.shape[0], size=2), :]
To replace (numpy 1.7.0 +):
A[np.random.choice(A.shape[0], 2, replace=False), :]
I do not believe that there is a good way to generate a random list without replacing up to 1.7. Perhaps you can customize a small definition that ensures that the two values ββdo not match.