vendredi 2 juillet 2021

How to generate a list of random numbers with many zero values in Python?

I want to add two list of random numbers in python. The first list is constructed with hundred random values. The second list should have only 4 or 5 random values and the rest of them should be 0. Then I want to add up these two list:

import random

#generating signal
signal = [10 * random.uniform(0,1) for i in range(100)]
peak = [100 * random.uniform(0,1) for i in range(100)] # something like [0 0 97.64 0 0 0 78.45 0 0 ... 0 24.26 0 ... 0]
result = signal + peak



Aucun commentaire:

Enregistrer un commentaire