title: Swig, returning an array of doubles
body: <p>I know, there are often many ways to solve certain problems. But here I know which way I want to have it, but I am unable to make it work with Python and SWIG...</p>
  
  <p>I have a C-function, which returns me an array of double values: </p>
  
  <pre><code>double *my(int x)
  {
     double a,b,*buf;
     buf = malloc (x * sizeof(double));
     a=3.14;
     b=2.7;
     buf[0]=a;
     buf[1]=b;
     return buf;
  }
  </code></pre>
  
  <p>Here, I definitively want to have the array as a return value. Not, as in many examples a 'void' function, which writes into an input array. Now, I would like to get a SWIG-python wrapper, which might be used as: </p>
  
  <pre><code>&gt;&gt;&gt; import example
  &gt;&gt;&gt; print example.my(7)
  [3.14,2.7]
  </code></pre>
  
  <p>Whatever I do, I have some conceptual problems here - I always get s.th. like <code>&lt;Swig Object of type 'double *' at 0xFABCABA12&gt;</code></p>
  
  <p>I tried to define some typemaps in my swg file: </p>
  
  <pre><code>%typemap(out) double [ANY] {
    int i;
    $result = PyList_New($1_dim0);
    for (i = 0; i &lt; $1_dim0; i++) {
      PyObject *o = PyFloat_FromDouble((double) $1[i]);
      PyList_SetItem($result,i,o);
    }
  }
  </code></pre>
  
  <p>But still I am unable to get out my results as required. Does anyone have a simple code-example to achieve this task?</p>