lundi 2 octobre 2017

How to use NumPy to create two subarrays from the randomized contents of a source array?

I have an array A, I want to create arrays B and C.

Basically, I want to randomly find 100 elements in A, put them in B and the rest in C.

If I use numpy.random.choice I can easily create B by just extracting all the elements in A that match the indices in the random list, but I would have to go through A again in order to find all the values that are not in B and put them in C. This works, but maybe there is a built-in function that can do this for me.

Is there a cheaper way?




Aucun commentaire:

Enregistrer un commentaire