title: Passing a C++ std::Vector to numpy array in Python
body: <p>I am trying a pass a vector of doubles that I generate in my <code>C++</code> code to a <code>python</code> numpy array. I am looking to do some downstream processing in <code>Python</code> and want to use some python facilities, once I populate the numpy array. One of the biggest things I want to do is to be able to plot things, and C++ is a bit clumsy when it comes to that. Also I want to be able to leverage Python's statistical power.</p>
  
  <p>Though I am not very clear as to how to do it. I spent a lot of time going through the Python C API documentation. I came across a function PyArray_SimpleNewFromData that apparently can do the trick. I still am very unclear as far as the overall set up of the code is concerned. I am building certain very simple test cases to help me understand this process. I generated the following code as a standlone Empty project in Visual Studio express 2012. I call this file Project1</p>
  
  <pre><code>#include &lt;Python.h&gt;
  #include "C:/Python27/Lib/site-packages/numpy/core/include/numpy/arrayobject.h"
  
  PyObject * testCreatArray()
  {
      float fArray[5] = {0,1,2,3,4};
      npy_intp m = 5;
      PyObject * c = PyArray_SimpleNewFromData(1,&amp;m,PyArray_FLOAT,fArray);
      return c; 
  }
  </code></pre>
  
  <p>My goal is to be able to read the PyObject in Python. I am stuck because I don't know how to reference this module in Python. In particular how do I import this Project from Python, I tried to do a import Project1, from the project path in python, but failed. Once I understand this base case, my goal is to figure out a way to pass the vector container that I compute in my main function to Python. I am not sure how to do that either.</p>
  
  <p>Any experts who can help me with this, or maybe post a simple well contained example of some code that reads in and populates a numpy array from a simple c++ vector, I will be grateful. Many thanks in advance.</p>