title: How to make up lost reference to declare a field (numpy)?
body: <p>Let's say I have class that contains a lot of fields and I want to make initializer that work for all fields so that I don't need to write an initializer for each of them.</p>
  
  <pre><code>class Foo():
      def __init__(n):
          self.n = n
          self.x = None
          self.m = None
          self.v = None
  </code></pre>
  
  <p>but method</p>
  
  <pre><code>def init_x(self, x):
      # initialize or erase x to zeros
      x = np.zeros(self.n)
  </code></pre>
  
  <p>doesn't work because <code>x=</code> loses reference to <code>x</code>. But </p>
  
  <pre><code>@staticmethod
  def get_x(x, i):
      return x[i]
  
  @staticmethod
  def set_x(x, i):
      x[i] = val
  </code></pre>
  
  <p>works. What could possibly make my <code>init_x</code> to work? I want to set the fields to None initially cuz there are other things that I depend on whether these fields are None or not.</p>
  
  <hr>
  
  <p>Re one of the comment, below doesn't work</p>
  
  <pre><code>from numpy import zeros
  
  class Foo:
    def __init__(self):
      self.x = None
  
    @staticmethod
    def foo(x):
      x[:] = zeros((10,4))
  
    def make(self):
      self.foo(self.x)
  
  
  f = Foo()
  f.make()
  print(f.x)
  </code></pre>
  
  <p>since</p>
  
  <pre><code>Traceback (most recent call last):
    File "python", line 16, in &lt;module&gt;
    File "python", line 12, in make
    File "python", line 9, in foo
  TypeError: 'NoneType' object does not support item assignment
  </code></pre>