+ 1

How to code a matrix composed of a certain amount of random binary lists?

I want for example to have Matrix =[[0,0,1,0,1,0,0,0,1,0], [0,1,0,0,0,1,0,1,1,0], [1,0,0,1,1,0,1,1,0,0]] And the program would kind of randomly changing this matrix lists into thus creating a new matrix with binary lists. Let's say m=[a, b, c] a =[0,0,1,0,1,0,0,0,1,0] b=[0,1,0,0,0,1,0,1,1,0] c=[1,0,0,1,1,0,1,1,0,0] How to generate a random a b c lists composed of binary? Thank you for your help guys! Keep calm and code!😊👍

2nd Apr 2019, 1:08 PM
Maximilien
Maximilien  - avatar
2 Antworten
+ 2
import random ls = [] row = 3 col = 10 for i in range(row): bin = [] for j in range(col): if random.randint(0, 1) == 0: bin.append(0) else: bin.append(1) ls.append(bin) print(ls)
2nd Apr 2019, 2:56 PM
Ankit
Ankit - avatar
+ 1
Thank you very much 🤗
2nd Apr 2019, 4:46 PM
Maximilien
Maximilien  - avatar