title: Accessing an unreturned list within a function in Python without disturbing Scipy
body: <p>Here is the code I'm working on. I'm trying to find the optimum alpha value to get the minimum MAE/MAD. With <code>scipy.optimize</code>, it works quite well. However, when <code>scipy.optimize</code> achieves the optimum alpha, it also achieves the forecast values that essentially I'm trying to get to. Is there a way to return or access and store those forecast values named <code>yPredList</code> without disturbing the work <code>scipy.optimize</code> is doing? Because otherwise I'm going to have to do the forecast calculations from scratch, which is unnecessary. Thanks.</p>
  
  <pre><code>import numpy as np 
  import scipy.optimize as spop
  ObservedSpeeds = [85, 64, 97 ,82, 12, 30, 47, 20, 45, 90, 60, 42, 50, 67, 28] #This is not the actual dataset, I actually have a data set of 525,600.
  def ErrorCalc(alpha,ObservedSpeeds):
      yPredList = [0,ObservedSpeeds[0]] #First prediction is 0 and the second prediction is the first observation
      for iters in range(2,len(ObservedSpeeds)):
          yPredList.append(np.multiply((1-alpha),yPredList[iters-1]) + np.multiply(alpha,ObservedSpeeds[iters-1]))
      NewList = [np.abs(y-o) for y,o in zip(yPredList,ObservedSpeeds)]
      NewError = np.mean(NewList)
      return NewError
  
  result = spop.minimize_scalar(ErrorCalc,bounds=[0,1],args=ObservedSpeeds,method='bounded')
  alpha = result.x
  </code></pre>