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)
output:
[0, 2, 2, 0, 0, 3]
[2, 0, 3, 1, 0, 1]
[2, 0, 0, 0, 3, 2]
[3, 1, 1, 0, 0, 3]
[3, 1, 2, 3, 0, 3]
[2, 3, 1, 0, 3, 1]
[3, 0, 2, 0, 2, 1]
[2, 2, 0, 1, 0, 0]
[1, 2, 1, 1, 3, 2]
[1, 0, 1, 3, 0, 3]
[[1, 0, 1, 3, 0, 3], [1, 0, 1, 3, 0, 3], [1, 0, 1, 3, 0, 3], [1, 0, 1, 3, 0, 3], [1, 0, 1, 3, 0, 3], [1, 0, 1, 3, 0, 3], [1, 0, 1, 3, 0, 3], [1, 0, 1, 3, 0, 3], [1, 0, 1, 3, 0, 3], [1, 0, 1, 3, 0, 3]]
`\`\`\``. Try and not use images.
– Maarten Bodewes Mar 14 '20 at 16:50