title: Counter Function in Python - Within a function
body: <p>I currently have the following 9x9 array:</p>
  
  <pre><code>m = np.zeros((9,9)) #9x9 grid of all zeros 
  vals = np.arange(1,10) #set of values from 1 to 9 aranged randomly
  for i in range(0,9):
      m[i,:] = np.random.choice(vals,size=9,replace=False) #randomly choses a set of 9 values for the row
  print(m.astype(int)) #prints as integers
  </code></pre>
  
  <p>Using this I have created a function called nonet_1:</p>
  
  <pre><code>def nonet_1():
      for i in range(0,3):
          for j in range(0,3):
              print(m[i,j])
  nonet_1()
  </code></pre>
  
  <p>I am wanting to use a similar idea, as below, using Counter function.</p>
  
  <pre><code>[r - 1 for r in Counter((m[:,i])).values()] #this line of code produces the scores based on n.o repeats in each column
  </code></pre>
  
  <p>The overall aim to count the number of duplications within this 3x3 grid in the nonet_1 function. Is there a simple way I can bring these together?</p>