title: How to convert a vector to numpy array with templates and boost?
body: <p>So I found <a href="https://stackoverflow.com/questions/10701514/how-to-return-numpy-array-from-boostpython">how to return numpy.array from boost::python?</a>. However, like this I have to write this function for int, float, double separately. Is it possible to avoid this using templates? I would somehow need to convert with T to an entry to the enumeration of NPY data types. Or are there other options?</p>
  
  <pre><code>template&lt;typename T&gt;
  boost::python::object getNumpyArray(std::vector&lt;T&gt;&amp; vector)
  {
      npy_intp shape[1] = { vector.size() };
      //Here I would need to replace NPY_DOUBLE with some conversion of T
      PyObject* obj = PyArray_SimpleNewFromData(1, shape, NPY_DOUBLE, vector.data());
      boost::python::handle&lt;&gt; handle(obj);
      boost::python::numeric::array arr(handle);
  
      return arr.copy();
  }
  </code></pre>