title: Create an Array of vectors in C++
body: <p>I want to create a distance matrix of a big dataset, and only want to store the 'close' enough elements. The code reads like this</p>
  
  <pre><code>vector&lt;double&gt; * D; 
  D = (vector&lt;double&gt; *) malloc(dim *sizeof(vector&lt;double&gt;) ) ;
  
  for(i=0;i&lt;dim;i++){
      for(j=i+1;j&lt;dim;j++){
          dx = s[j][0] - s[i][0];
          dy = s[j][1] - s[i][1];
          d =   sqrt( dx*dx + dy*dy );
          if(d  &lt; MAX_DISTANCE){
              D[i].push_back(d);
              D[j].push_back(d);
              }
          }
  </code></pre>
  
  <p>which gives me segmentation fault. I guess I have not defined the array of vector correctly. How do I get around this  ? </p>