0

I want a list of 2D arrays(or matrices) where the values can be modified in each of its elements individually. So, I did the following :

w=zeros((3,3)), v=3*[w], v[1][1,1]=1

But the result I get is that the (1,1)th element of each of the 3 entries of v are changed to 1. How do I solve this issue? I tried converting it to matrix but it didn't help.

Circle
  • 1
  • 2
  • Your list `v` is not a list of 3 different arrays, but a list of 3 references to the same array. Do `v = [zeros((3,3)), zeros((3,3)), zeros((3,3))]` or `v = [zeros((3,3)) for i in range(3)]` – PaulMcG Jul 18 '18 at 04:22
  • Thanks, it worked. I thought it doesn't have memory of where it came from – Circle Jul 18 '18 at 05:36
  • Read the answers on the duplicate question for more info. – PaulMcG Jul 18 '18 at 05:37

0 Answers0