title: Smoothing values (neighbors between 1-9)
body: <p><strong>Instructions:</strong> Compute and store R=1000 random values from 0-1 as x.    moving_window_average(x, n_neighbors) is pre-loaded into memory from  3a. Compute the moving window average for x for the range of    n_neighbors 1-9. Store x as well as each of these averages as    consecutive lists in a list called Y.</p>
  
  <p><strong>My solution:</strong></p>
  
  <pre><code>R = 1000
  n_neighbors = 9
  
  x = [random.uniform(0,1) for i in range(R)]
  Y = [moving_window_average(x, n_neighbors) for n_neighbors in range(1,n_neighbors)] 
  </code></pre>
  
  <p>where moving_window_average(x, n_neighbors) is a function as follows:</p>
  
  <pre><code>def moving_window_average(x, n_neighbors=1):
      n = len(x)
      width = n_neighbors*2 + 1
      x = [x[0]]*n_neighbors + x + [x[-1]]*n_neighbors
      # To complete the function,
      # return a list of the mean of values from i to i+width for all values i from 0 to n-1.
      mean_values=[]
      for i in range(1,n+1):
          mean_values.append((x[i-1] + x[i] + x[i+1])/width)
      return (mean_values)
  </code></pre>
  
  <p>This gives me an error, <strong>Check your usage of Y again.</strong> Even though I've tested for a few values, I did not get yet why there is a problem with this exercise. Did I just misunderstand something? </p>