Numpy: Get random set of rows from 2D array

后端 未结 8 2088
挽巷
挽巷 2020-11-28 01:49

I have a very large 2D array which looks something like this:

a=
[[a1, b1, c1],
 [a2, b2, c2],
 ...,
 [an, bn, cn]]

Using numpy, is there a

8条回答
  •  误落风尘
    2020-11-28 02:40

    This is an old post, but this is what works best for me:

    A[np.random.choice(A.shape[0], num_rows_2_sample, replace=False)]
    

    change the replace=False to True to get the same thing, but with replacement.

提交回复
热议问题