title: Numpy array assignment inside class
body: <p>I am using Python 3.2.3 with NumPy 1.6.1.
  I would be very grateful if someone could explain me what does NumPy do when I try to access (in two different ways) an element of a NumPy array.</p>
  
  <p><strong>Code</strong>:</p>
  
  <pre><code>import numpy as np
  
  class MyClass:
  
      def __init__(self,q):
          self.coord = q
          self.firstel = q[0]
          self.secondel = q[1:2]
  
  q = np.array([10,20])   # numpy array
  my_object = MyClass(q)  # object of MyClass
  
  print('original','q:',q,' / coord:',my_object.coord,' / 2elements:',my_object.firstel,my_object.secondel])
  
  q[0],q[1] = 30,40 # modification of the  elements of q
  
  print('modified','q:',q,' / coord:',my_object.coord,' / elements:', my_object.firstel, my_object.secondel])
  </code></pre>
  
  <p><code>q</code> is a numpy array that I pass as an argument to <code>MyClass</code>. I store it in a variable called <code>coord</code> inside the class. Then I access the first and the second element of <code>q</code> in two different ways inside the class.</p>
  
  <p>When I run the code above, I get this:</p>
  
  <pre><code>original q: [10 20]  / coord: [10 20]  / elements: [10, array([20])]
  modified q: [30 40]  / coord: [30 40]  / elements: [10, array([40])]
  </code></pre>
  
  <p>The variable <code>firstel</code> <strong>is not updated</strong> when <code>q</code> is changed but the variable <code>secondel</code> <strong>is</strong>.</p>
  
  <p>What happened with <code>q[0]</code> and <code>q[1:2]</code> ?</p>
  
  <p>Thanks</p>