title: Numpy object arrays
body: <p>I've recently run into issues when creating Numpy object arrays using e.g.</p>
  
  <pre><code>a = np.array([c], dtype=np.object)
  </code></pre>
  
  <p>where c is an instance of some complicated class, and in some cases Numpy tries to access some methods of that class. However, doing:</p>
  
  <pre><code>a = np.empty((1,), dtype=np.object)
  a[0] = c
  </code></pre>
  
  <p>solves the issue. I'm curious as to what the difference is between these two internally. Why in the first case might Numpy try and access some attributes or methods of <code>c</code>?</p>
  
  <p>EDIT: For the record, here is example code that demonstrates the issue:</p>
  
  <pre><code>import numpy as np
  
  class Thing(object):
  
      def __getitem__(self, item):
          print "in getitem"
  
      def __len__(self):
          return 1
  
  a = np.array([Thing()], dtype='object')
  </code></pre>
  
  <p>This prints out <code>getitem</code> twice. Basically if <code>__len__</code> is present in the class, then this is when one can run into unexpected behavior.</p>