title: Most efficient property to hash for numpy array
body: <p>I need to be able to store a <code>numpy</code> <code>array</code> in a <code>dict</code> for caching purposes.  Hash speed is important.</p>
  
  <p>The <code>array</code> represents indicies, so while the actual identity of the object is not important, the value is.  Mutabliity is not a concern, as I'm only interested in the current value.</p>
  
  <p>What should I hash in order to store it in a <code>dict</code>?</p>
  
  <p>My current approach is to use <code>str(arr.data)</code>, which is faster than <code>md5</code> in my testing.</p>
  
  <hr>
  
  <p>I've incorporated some examples from the answers to get an idea of relative times:</p>
  
  <pre><code>In [121]: %timeit hash(str(y))
  10000 loops, best of 3: 68.7 us per loop
  
  In [122]: %timeit hash(y.tostring())
  1000000 loops, best of 3: 383 ns per loop
  
  In [123]: %timeit hash(str(y.data))
  1000000 loops, best of 3: 543 ns per loop
  
  In [124]: %timeit y.flags.writeable = False ; hash(y.data)
  1000000 loops, best of 3: 1.15 us per loop
  
  In [125]: %timeit hash((b*y).sum())
  100000 loops, best of 3: 8.12 us per loop
  </code></pre>
  
  <p>It would appear that for this particular use case (small arrays of indicies), <code>arr.tostring</code> offers the best performance.</p>
  
  <p>While hashing the read-only buffer is fast on its own, the overhead of setting the writeable flag actually makes it slower.</p>