samedi 14 mars 2020

Python lists and random number [duplicate]

I am tryng to generate some arrays with random numbers and then put those arrays in another array one after another. but instead of putting them one after another my code is putting the last array generated in all the fields of the 2d array. Please help I cant identify the problem.

example for the code below: the inner loop makes an array with random number [1,0,2,3] then this array is put in another array where the index is the range of numbers in the first loop.

import random
arr=[0 for i in range(0,6)]
arr2=[]

for j in range(0,10):
    for l in range(0,6):
        arr[l]=random.randrange(0,4,1)
    print(arr)
    arr2.append(arr)

print(arr2)

enter image description here




Aucun commentaire:

Enregistrer un commentaire