title: code conversion from matlab to python
body: <p>I am converting matlab file to python code. my matlab file is : </p>
  
  <pre><code>function [q,len] = curve_to_q(p)
  
  [n,N] = size(p);
  for i = 1:n
      v(i,:) = gradient(p(i,:),1/(N)); 
  end
  
  len = sum(sqrt(sum(v.*v)))/N;
  v = v/len;
  for i = 1:N
      L(i) = sqrt(norm(v(:,i)));
      if L(i) &gt; 0.0001
          q(:,i) = v(:,i)/L(i);
      else
          q(:,i) = v(:,i)*0.0001;
      end
  end
  </code></pre>
  
  <p>converted code is : </p>
  
  <pre><code>from __future__ import division
  import numpy as np
  from scipy.io import loadmat,savemat
  import os
  
  def curve_to_q(p):
      n, N = p.shape # nargout=2
      for i in range(1, (n +1)):
          v[(i -1), :] = np.gradient(p[(i -1), :], 1 / (N))
      len_ = np.sum(np.sqrt(np.sum(v.np.dot(v)))) / N
      v = v / len_
      for i in range(1, (N +1)):
          L[(i -1)] = sqrt(norm(v[:, (i -1)]))
          if L[(i -1)] &gt; 0.0001:
              q[:, (i -1)] = v[:, (i -1)] / L[(i -1)]
          else:
              q[:, (i -1)] = v[:, (i -1)] * 0.0001
      return q, len_
  </code></pre>
  
  <p>But, there seems to be problem in </p>
  
  <pre><code>len_ = np.sum(np.sqrt(np.sum(v.np.dot(v)))) / N
  </code></pre>
  
  <p>and </p>
  
  <pre><code>L[(i -1)] = sqrt(norm(v[:, (i -1)]))
  </code></pre>
  
  <p>how can i make it proper conversion to python?</p>