title: Replacing NumPy array entries with their frequencies / values from dictionary
body: <p>Problem: From two input arrays, I want to output an array with the frequency of True values (from input_2) corresponding to each value of input_1.</p>
  
  <pre><code>import numpy as np   # import everything from numpy
  from scipy.stats import itemfreq
  input_1 = np.array([3,6,6,3,6,4])
  input_2 = np.array([False, True, True, False, False, True])
  </code></pre>
  
  <p>For this example output that I want is:</p>
  
  <pre><code>output_1 = np.array([0,2,2,0,2,1])
  </code></pre>
  
  <p>My current approach involves editing input_1, so only the values corresponding to True remain:</p>
  
  <pre><code>locs=np.where(input_2==True,input_1,0)
  </code></pre>
  
  <p>Then counting the frequency of each answer, creating a dictionary and replacing the appropriate keys of input_1 to values (the True frequencies).</p>
  
  <pre><code>loc_freq = itemfreq(locs)
  dic = {}
  for key,val in loc_freq:
      dic[key]=val
  print dic
  for k, v in dic.iteritems():
      input_1[input_1==k]=v
  </code></pre>
  
  <p>which outputs [3,2,2,3,2,1].</p>
  
  <p>The problem here is twofold: 
  1) this still does not do anything with the keys that are not in the dictionary (and should therefore be changed to 0). For example, how can I get the 3s transformed into 0s?
  2) This seems very inelegant / ineffective. Is there a better way to approach this?</p>