vendredi 23 août 2019

how to shuffle a binary array a specific amount

I have a binary array. I want to shuffle it such that n percent of random elements stay in the same place and the rest get shuffled. Another way of putting it is, I have a binary array and I want to create a second array that is of same length and n percent similar when compared to the first using difflib

I'm using random.shuffle to shuffle the array but can't find info on the percent part of my question.

import random

array = [1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0]
random.shuffle(array)
print(array)




Aucun commentaire:

Enregistrer un commentaire