I tried creating Identity matrix, but there was a problem creating a 2D array (list inside a list so to say) that can be determined by an input/parameter.
I expected from this:-
def eye(limit):
lst = [[0] * limit] * limit
for i in range(limit):
lst[i][i] =1
return lst
for item in eye(4):
print(item)
to output this:-
[1, 0, 0, 0]
[0, 1, 0, 0]
[0, 0, 1, 0]
[0, 0, 0, 1]
but instead, go this:-
[1, 1, 1, 1]
[1, 1, 1, 1]
[1, 1, 1, 1]
[1, 1, 1, 1]
I tried to create a fixed 4x4 array, and it surprisingly worked and out-putted the expected answer.
And lead me to think that by multiplying a list won't create another list and concatenate them, but instead printing them by the number they got multiplied of. What do you think and how can i create a variable one.