1

I am trying to create an array based on another, but I want to keep the original array. I tried this but original array is modified, and I dont know why

k1=[[1,2],[3,4]]
def foo(k):
    k2=k
    for i in range(len(k2)):
        k2[i]=np.append(k2[i],i+10)
    return k2
jmparejaz
  • 160
  • 1
  • 14
  • In your function, `k1` is a global, not the argument `k`. You don't do anything with `k`. `k1` is a list of lists, but you use `np.append`, which creates an array. Why? `np.append` is not a good function for beginners. It's often used wrong. – hpaulj Oct 19 '16 at 05:25
  • 1
    thanks for your answer, i found out what was the problem and solved like this k2=k[:] – jmparejaz Oct 19 '16 at 05:56

0 Answers0