title: Count of the number of identical values in two arrays for all the unique values in an array
body: <p>I have two arrays A and B. A has multiple values (these values can be string or integer or float) and B has values 0 and 1. I need, for each unique value in A, the count of points that coincide with the 1s in B and the 0s in B. Both the counts need to be stored as separate variables.
  For example: </p>
  
  <pre><code>A = [1, 1, 3, 2, 2, 1, 1, 3, 3] # input multivalue array; it has three unique values – 1,2,3
  B = [0, 0, 0, 1, 1, 1, 0, 1, 0] # input binary array
  #Desired result: 
  countA1_B1 = 1 #for unique value of '1' in A the count of places where there is '1' in B
  countA1_B0 = 3 #for unique value of '1' in A the count of places where there is '0' in B
  countAno1_B1 = 3 #for unique value of '1' in A the count of places where there is no '1' in A but there is '1' in B 
  countAno1_B0 = 2 #for unique value of '1' in A the count of places where there is no '1' in A and there is '0' in B 
  </code></pre>
  
  <p>I need this for all the unique values in A. The A array/list would be a raster and hence the unique values will not be known. So the code would first extract the unique values in A and then do the remaining calculations
  My approach to solving this (see post <a href="https://stackoverflow.com/questions/57092715/creating-n-number-of-masked-subarrays-for-all-the-n-unique-values-in-an-array-us/57095973?noredirect=1#comment100843266_57095973">previous question</a>:)</p>
  
  <pre><code>Import numpy as np
  A = [1, 1, 3, 2, 2, 1, 1, 3, 3] # input array
  B = [0, 0, 0, 1, 1, 1, 0, 1, 0] # input binary array
  A_arr = np.array(A)
  A_unq = np.unique(A_arr)
  #code 1    
  A_masked_arrays = np.array((A_arr[None, :] == A_unq[:, None]).astype(int)) 
  #code 2
  # A_masked_arrays = [(A==unique_val).astype(int) for unique_val in
  np.unique(A)]
  print(A_masked_arrays) 
  out = {val: arr for val, arr in zip(list(A_unq), list(A_arr))} 
  #zip() throws error
  #TypeError: 'zip' object is not callable. 
  dict = {}
  for i in A_unq:
      for j in A_masked_arrays:
          dict = i, j
          print(dict)
  </code></pre>
  
  <p>Result obtained:</p>
  
  <pre><code># from code 1
  [[1 1 0 0 0 1 1 0 0]
   [0 0 0 1 1 0 0 0 0]
   [0 0 1 0 0 0 0 1 1]]
  # from code 2
  [array([1, 1, 0, 0, 0, 1, 1, 0, 0]), array([0, 0, 0, 1, 1, 0, 0, 0, 0]), 
  array([0, 0, 1, 0, 0, 0, 0, 1, 1])]
  </code></pre>
  
  <p>Using dictionary creation I get this result</p>
  
  <pre><code>(1, array([1, 1, 0, 0, 0, 1, 1, 0, 0]))
  (1, array([0, 0, 0, 1, 1, 0, 0, 0, 0]))
  (1, array([0, 0, 1, 0, 0, 0, 0, 1, 1]))
  (2, array([1, 1, 0, 0, 0, 1, 1, 0, 0]))
  (2, array([0, 0, 0, 1, 1, 0, 0, 0, 0]))
  (2, array([0, 0, 1, 0, 0, 0, 0, 1, 1]))
  (3, array([1, 1, 0, 0, 0, 1, 1, 0, 0]))
  (3, array([0, 0, 0, 1, 1, 0, 0, 0, 0]))
  (3, array([0, 0, 1, 0, 0, 0, 0, 1, 1]))
  </code></pre>
  
  <p>This is where I am stuck up. From here how to get to the final count of each unique value in A as countA1_B1, countA1_B0, countAno1_B1, countAno1_B0 and so on. Need help with this. Thanks in advance.</p>