title: Implementing Python integer key and value numpy dictionary
body: <p>I have a large amount of data which I need to lookup quickly and usually I would use a dictionary. However, I need to store around 600million key-value pairs and when trying to store this in a dictionary it didn't fit in memory.</p>
  
  <p>I realised that a dictionary could save on memory if it stored the key and values as integers with a fixed length (i.e. 32bit). I can solve my problem by using numpy arrays, sorting the data and then using a search to find the right values (takes up around 8GB):</p>
  
  <pre><code>import numpy as np    
  key_a = np.zeros(600e6, dtype=np.int64)
  values_a = np.zeros(600e6, dtype=np.int32)
  
  # ... Fill arrays ...
  
  # Find value using key:
  index = np.searchsorted(key_a, key_to_find)    
  value_to_find = values_a[index]
  </code></pre>
  
  <p>This approach isn't as fast as using a hash.</p>
  
  <p>What I would ideally like to do is implement a dictionary but using fixed size numpy arrays as the backbone to save on space? I also want the dictionary to be optimised for intergers. Why doesn't numpy already offer something like this and how would I go about doing this?</p>