title: Vectorized dictionary in Python
body: <p>Is there any package in Python that provides a dictionary for vectorized access with NumPy arrays? I am looking for something like this:</p>
  
  <pre><code>&gt;&gt;&gt; vector_dict = VectorizedDict({1: "One",
  ...                               2: "Two",
  ...                               3: "Three"},
  ...                               dtype_key=int, dtype_val="U5")
  &gt;&gt;&gt; a = np.array([1,2,3]),
  &gt;&gt;&gt; b = vector_dict[a]
  &gt;&gt;&gt; print(type(b))
  np.ndarray
  &gt;&gt;&gt; print(b)
  ["One", "Two", "Three"]
  </code></pre>
  
  <p>Although this result would also be possible to achieve by iterating over the array elements, the iteration approach would be rather inefficient for large arrays.</p>
  
  <p>EDIT:</p>
  
  <p>For small dictionaries I use the following approach:</p>
  
  <pre><code>for key, val in my_dict.items():
      b[a == key] = val
  </code></pre>
  
  <p>Although the boolean masking is quite efficient when iterating over small dictionaries, it is time consuming for large dictionaries (thousands of key-value-paris).</p>