kangwonlee / nmisp

Numerical Methods in SciPy
Other
11 stars 62 forks source link

Referencing in python lists #163

Open kangwonlee opened 2 years ago

kangwonlee commented 2 years ago
import pprint
A = [[0]*3]*3
pprint.pprint(A, width=15)
A[0][0] = 1
pprint.pprint(A, width=15)
kangwonlee commented 2 years ago
import pprint

def new_mat(n_row, n_col):
  result = [None] * n_row

  for i in range(n_row):
    result[i] = [0.0] * n_col

  return result

B = new_mat(3, 3)
pprint.pprint(B, width=20)

B[0][0] = 3.0
pprint.pprint(B, width=20)
kangwonlee commented 2 years ago