Numpy: How to randomly split/select an matrix into n-different matrices

前端 未结 4 748
攒了一身酷
攒了一身酷 2021-02-05 16:00
  • I have a numpy matrix with shape of (4601, 58).
  • I want to split the matrix randomly as per 60%, 20%, 20% split based on number of rows
  • This is for Machin
4条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-05 16:33

    you can use numpy.random.shuffle

    import numpy as np
    
    N = 4601
    data = np.arange(N*58).reshape(-1, 58)
    np.random.shuffle(data)
    
    a = data[:int(N*0.6)]
    b = data[int(N*0.6):int(N*0.8)]
    c = data[int(N*0.8):]
    

提交回复
热议问题