Addition of multidimensional vectors C++
<p>Having a bit of a headache trying to sum the elements in a 3d Vector.</p>

<p>Its for a k-means algorithm that I'm currently programming; an algorithm that I understand and can do on paper, but syntactically has me a bit tongue tied at the moment. I might mention that this project is the first time that I've really dealt with complex containers in C++. Currently I want calculate the new centroid for my points in a cluster, this is done by averaging the positions of every co-ordinate in the cluster. My 3d vector is set out as a vector of clusters each containing a vector which contain vectors of my co-ordinates in that cluster (I hope that sounds clear, hopefully my code will alleviate any confusion). I'm trying to use iterators at the moment, but am considering going back to ints and indices as I am more comfortable with them, though I feel that I should learn how this syntax works as it seems to be important and powerful. </p>

<p>I'll post just the function that I'm stuck on and the parts of the header that relate to it. If you would like to see any of the other code I'm happy to throw that in too on request, but I feel that this should be enough to show my problem. </p>

<pre><code>.h file parts (public members of class):

vector&lt; vector &lt; vector &lt;float&gt; &gt; &gt; clusters; 
vector&lt;vector&lt;float&gt; &gt; avg;
int avgDiv;




.cpp file part with comments to help elaborate my query:

    vector&lt;vector&lt;vector&lt;float&gt; &gt; &gt;::iterator threeD;
    vector&lt;vector&lt;float&gt; &gt;::iterator row;
    vector&lt;float&gt;::iterator col;

    for (threeD = clusters.begin(); threeD != clusters.end(); threeD++) {
        for (row = threeD-&gt;begin(); row != threeD-&gt;end(); row++) {
            for(col = row-&gt;begin(); col != row-&gt;end(); col++){

             //its this code below that is causing my headache, 
             //I know that what is written isn't correct, 
             //it is there to serve as an example of what I've 
             //been trying to do to sort out my issue. 

             avg.at(row) ( = or push_back ) ((clusters.at(row).at(col)) + (clusters.at(row+1).at(col))); 

            }

            avgDiv = distance(row-&gt;begin(),row-&gt;end());
            //divide each value in avg vector by the amount of members in row, giving the new centroid for that cluster, loop forward to next cluster. this isn't a problem I should think. 

        }
    }
</code></pre>

<p>My problem is that the compiler tells me that call to 'at' is not a member function. Now from what I can see from other questions it is because I'm not passing the right object as an arguement, though, I'm sure that I want to add together every element in the vector which the iterators are at together with the element next in the row. </p>

<p>I've tried and make this as clear as possible, please ask and I will add as much detail as I can to help you answer. I am new to this, and am very happy to take criticism; it will only make me a better programmer. Thank you for your time.  </p>
