title: Why do I explicitly need to .copy() a numpy array/list?
body: <p>Why do I have to <code>.copy()</code> a numpy array (or list, though those don't have <code>.copy()</code> but make for a good minimal example) when I want to get an independend copy of it, while I don't have to do so with a variable? <strong>What's the reason for this behaviour?</strong></p>
  
  <p>E.g. setting <code>a = 1</code> and <code>b = a</code> and then setting <code>b = 2</code> does not change <code>a</code>, whereas <code>a=([0])</code>, <code>b = a</code> and <code>b[0]=1</code> also changes <code>a</code>.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>It appears that this is a very common issue/question that can be asked in various ways, so I couldn't find it. For a quick <em>"I just need to understand what's happening so that I can move on"</em> I guess the answer (and the answers to the other same/similar questions) are good enough. For a better understanding I guess <a href="https://nedbatchelder.com/text/names1.html" rel="nofollow noreferrer">this</a> link provided by @chthonicdaemon in the comments seems like a good starting point for me.</p>
  
  <p><strong>longer Background</strong></p>
  
  <p>In many situations I have to set up a numpy array with some starting values which then gets filled with other values while my program runs. I.e.</p>
  
  <pre><code>logger = np.zeros(5)
  #various things happen
  logger[0] = 1
  #more stuff happens
  logger[3] = 1
  </code></pre>
  
  <p>you get the idea.</p>
  
  <p>But often it is desirable to have the base array preserved in order to be able to compare the results to it, so I just set up the base first and then make copies from it. So I would expect that I simply could set it up like this:</p>
  
  <pre><code>base = np.zeros(5)
  logger = base
  logger[0] = 1
  </code></pre>
  
  <p>so that </p>
  
  <pre><code>In [1]:base
  Out[1]:array([ 0.,  0.,  0.,  0.,  0.])
  In [2]:logger
  Out[2]:array([ 1.,  0.,  0.,  0.,  0.])
  </code></pre>
  
  <p>However with the above array, they stay "connected", so that I get</p>
  
  <pre><code>In [1]:base
  Out[1]:array([ 1.,  0.,  0.,  0.,  0.])
  </code></pre>
  
  <p>I can fix that by explicitly using</p>
  
  <pre><code>logger = base.copy()
  </code></pre>
  
  <p>but I'm wondering why I have to.</p>