title: solving a minimization problem using scipy.optimize in python
body: <p>I have a question regarding solving a minimization problem using <code>scipy.optimize</code> in python. I have an 1-D array (<code>x</code>) containing about 2000 elements as the variables of this problem, and a <code>list</code> of <code>{constraint,dict}</code>elements as the constraints of the optimization problem.<br />The issue is that I want to calculate the sum of a large number of variables within a <code>for</code> loop to define objective function and the constraints. I have attached a simple example of my code below, but it should be considered that according to the complication of my code, it is not possible to do the calculation without <code>for</code> loops. However, by doing this, I face with this error: <code>'function' object is not iterable</code>.  <br /></p>
  <pre><code>def objective(x):
      sum = 0
      for i in range(1, 1000):
          sum += x[i]
      return sum
  
  def constraints(x):
      constraint = []
      for i in range(1, 1000):
          sum = 0
          for j in range(1, 100):
              sum += j*x[i]
          constraint.append({'type': 'ineq', 'fun': 10 - sum})
      return constraint
  sol = minimize(objective, x0, method='slsqp', constraints=constraints)
   
  </code></pre>