title: fitting a plane into a cloud of points (3d)
body: <p>I have a data file containing multiple columns of data,I would like to extract 3 columns (that indicate the coordinates ) out of this data file and put them in another file, then using the newly created file I would like to fit a plane or surface (or whatever you would like to call it) using scipy.optimize.curve_fit. Here is my code:</p>
  
  <pre><code># -*- coding: utf-8 -*-
  
  from pylab import *
  import matplotlib.pyplot as plt 
  import numpy as np
  from scipy import stats
  from scipy.optimize import curve_fit
  
  
  
  ### processing function    
  def store(var,textfile):
      data=loadtxt(textfile,skiprows=1)
      p0=[]
      p1=[]
      p2=[]
      for i in range(0,len(data)):
          p0.append(float(data[i,2]))
          p1.append(float(data[i,3]))
          p2.append(float(data[i,4]))
      var.append(p0)
      var.append(p1)
      var.append(p2)
  
  #extracting the data from a textfile
  datafile1='cracks_0101005_5k_tensionTestCentreCrack_l0.001a0_r0.01.txt'
  a1=[]
  store(a1, datafile1)
  
  
  rcParams.update({'legend.numpoints':1,'font.size': 20,'axes.labelsize':25,'xtick.major.pad':10,'ytick.major.pad':10,'legend.fontsize':14})
  lw=2
  ms=10
  
  #fitting a surface(curve) into the data
  
  def func(data, m, n, o): 
      return m*data[:,0] + n*data[:,2] + o 
  
  guess=(1,1,1)
  
  params, pcov = curve_fit(func, a1[::2, :2], a1[:,1], guess)
  print (params)
  </code></pre>
  
  <p>And I am getting the following error message:</p>
  
  <pre><code>Traceback (most recent call last):
    File "fitcurve.py", line 41, in &lt;module&gt;
      params, pcov = curve_fit(func, a1[::2, :2], a1[:,1], guess)
  TypeError: list indices must be integers, not tuple
  </code></pre>
  
  <p>Would you please tell me what I am doing wrong?</p>
  
  <p>Just to make it more clear :
  I am trying to have Y as my dependent function, so it would be a function of X and Z.
  Apparently <code>a1[]</code> is a list and not an array right?
  But even when I change it to an array <code>Myarray=np.asarray(a1)</code> I get some other weird messages.
  I would appreciate if someone could help me understand the issue here.</p>
  
  <p>Cheers</p>