lundi 2 septembre 2019

How could I fill my second list with zero and one according to the conditions below?

I have a list contains multiple lists. It's full of random numbers between 0 and 1. I need to create another list with the same size of the first one, but if the random numbers less or equal to 0.75, I need them equal to zero and the more than 0.75 will be one. I always get a list full of zeros, where is my fault?

This is below my try:

import random

y = [[random.uniform(0,1) for i in range(10)]for j in range(10)]
x = [[0 for i in range(len(y[0]))]for j in range(len(y))]

for i in range(len(y)):
    for j in range(len(y[0])):
        if y[i][j] <= 0.75:
            x[i][j] == 0
        else:
            x[i][j] == 1
print(x)




Aucun commentaire:

Enregistrer un commentaire