title: Calculating numpy.mean with array?
body: <p>I'm trying define a procedure that calculates mean of daily returns for every security:</p>
  
  <pre><code>import csv
  import numpy as np
  
  def security_mean(com):
      CSV = csv.reader(open("my_file.csv","rb"))
      foo = False
      old = 0
      new = 0
      mean = []
      for row in CSV:
          try:
              if foo == True:
                  old = float(row[-1])
                  x = (new - old) / old
                  mean.append(x)
                  new = float(row[-1])
                  foo = True
              else:
                  new = float(row[-1])
                  foo = True
          except ValueError:
              string = row[-1]
              continue
      value = np.mean(mean)
      print string + ' mean: ' + str(value)
  </code></pre>
  
  <p>Here is <code>my_file.csv</code>:</p>
  
  <pre><code>Date    Open    High    Low Close           Volume    Adj Close
  2013-09-27  874.82  877.52  871.31  876.39  1258800    876.39
  2013-09-26  878.3   882.75  875 878.17  1259900        878.17
  2013-09-25  886.55  886.55  875.6   877.23  1649000    877.23
  2013-09-24  886.5   890.1   881.4   886.84  1467000    886.84
  2013-09-23  896.15  901.59  885.2   886.5   1777400    886.5
  2013-09-20  898.39  904.13  895.62  903.11  4345300    903.11
  2013-09-19  905.99  905.99  895.4   898.39  1597900    898.39
  2013-09-18  886.35  903.97  883.07  903.32  1934700    903.32
  2013-09-17  887.41  888.39  881 886.11  1259400        886.11
  2013-09-16  896.2   897 884.87  887.76  1336500        887.76
  </code></pre>
  
  <p>Can I make my function smaller using array? How?</p>
  
  <p>Thanks.</p>
  
  <p><strong>NOTE:</strong> daily return formula: <strong>(x - y)/y</strong> or  <strong>(x / y) - 1</strong> ; where x = today Adj close, and y = yesterday Adj close</p>