1

I am sorry that the title of this question is vague. I could not find an appropriate statement for my question. I have been struggling with something in python. I have an array which I enter python manually. Then I want to use it inside a function and I want to put the function inside a while loop. My code is something like this:

C=[8592,2092,9284,1136,8267,349,5623,2034,2834,4404]
def h(x):
  Emp=C
  .
  .
  . 
  Emp=Emp-xxxx
  return xxx
while xxxx:
  xxx=h(x)

well the problem starts from here. I want to keep C unchanged during the whole process but unfortunately values of C change with variability in values of Emp. I have never faced such a problem in Matlab and I cant understand why this is happening in Pyhton. Any help is appreciated.

Fairy
  • 379
  • 1
  • 5
  • 17

1 Answers1

1

I want to keep C unchanged during the whole process

Your issue is Emp = C, in Python this creates a reference to C, it doesn't copy it like some statistical computation languages do with that syntax

You can copy C with

import copy

x = copy.copy(C)
while condition:
    h(x)
bakkal
  • 54,350
  • 12
  • 131
  • 107