Say I have two unique arrays:
a = [1,20,21, 67,4, 20, 90, 54,90, 78]
b= [3, 654, 342, 309, 245, 213, 984, 56, 89, 23]
If I pass the value "20%", I want to randomly replace 20% of the values in array a with the values in the array b for the same indices.
Output:
a = [3, 20, 21, 67, 4, 20, 90, 54, 90, 23]
Here is what I have tried:
a = [1,20,21, 67,4, 20, 90, 54,90, 78]
b= [3, 654, 342, 309, 245, 213, 984, 56, 89, 23]
percentage = 0.2
no_of_replaced_values = int(len(a)*percentage)
sl = slice(0, no_of_replaced_values)
a[0:no_of_replaced_values]=b[sl]
print(a)
This gives an output of a= [3, 654, 21, 67, 4, 20, 90, 54, 90, 78]
. Instead of consecutive values being changed, I want to randomly change them.