vendredi 4 septembre 2015

split randomly a list of array in Python

i have a list of array in Python

import numpy as np
mylist = [np.random.randint(0, i, int(10)) for i in (10,100,3)]
[array([5, 5, 7, 2, 0, 5, 7, 8, 6, 9]), array([42, 70, 30, 62, 44,  8, 40, 68, 46, 93]), array([0, 0, 0, 0, 0, 1, 2, 0, 1, 2])]

i wish to divide (if possible randomly) for example 50% in two lists

list_one = [array([5, 5, 7, 2, 0]), array([42, 70, 30, 62, 44]), array([0, 0, 0, 0, 0])]
list_two = [array([5, 7, 8, 6, 9]), array([8, 40, 68, 46, 93]), array([1, 2, 0, 1, 2])]

or 30% and 70%

list_one = [array([5, 5, 7]), array([42, 70, 30]), array([0, 0, 0])]
list_two = [array([2, 0, 5, 7, 8, 6, 9]), array([62, 44,  8, 40, 68, 46, 93]), array([0, 0, 1, 2, 0, 1, 2])]




Aucun commentaire:

Enregistrer un commentaire