I have the following code: https://repl.it/repls/RottenGiddyInitializationfile
from math import *
def weights(p1,p2,p3):
n =len(p1)
rows, cols = (n, n)
w = [[0]*cols]*rows
for i in range(n):
for j in range(n):
if i != j:
w[i][j] += p1[i] * p1[j]
for i in range(n):
for j in range(n):
if i != j:
w[i][j] += p2[i] * p2[j]
for i in range(n):
for j in range(n):
if i != j:
w[i][j] += p3[i] * p3[j]
print("old")
print(w)
new = [[0]*cols]*rows
for i in range(n):
for j in range(n):
w[i][j] = w[i][j] + 1
print("new")
return w
six=[1,1,-1,1,1,1,1,-1,1,1,-1]
three=[1,-1,1,1,-1,1,1,1,1,-1,-1]
one=[-1,-1,1,-1,-1,1,-1,1,-1,-1,-1]
w= weights(three,six,one)
print(w)
As evident from the console, the old value for w
is some matrix of ints
I update every element by 1.
However, the code increases the value of each element by 10.
Is this a bug in python, or am I doing it incorrectly?