Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7636743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:45:45+00:00 2026-05-31T07:45:45+00:00

Having a bit of a headache trying to sum the elements in a 3d

  • 0

Having a bit of a headache trying to sum the elements in a 3d Vector.

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.

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.

.h file parts (public members of class):

vector< vector < vector <float> > > clusters; 
vector<vector<float> > avg;
int avgDiv;




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

    vector<vector<vector<float> > >::iterator threeD;
    vector<vector<float> >::iterator row;
    vector<float>::iterator col;

    for (threeD = clusters.begin(); threeD != clusters.end(); threeD++) {
        for (row = threeD->begin(); row != threeD->end(); row++) {
            for(col = row->begin(); col != row->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->begin(),row->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. 

        }
    }

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.

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:45:47+00:00Added an answer on May 31, 2026 at 7:45 am

    avg.at(index) is used with an integer index, it’s just the ‘c’ array[index] notation with bounds checking – incidentally in real code you want to use [] or disable checking for speed.

    But row is an iterator, effectively it’s a pointer to the element in avg already so just dereference it to get the value.

    *row = value of avg at position of iterator 'row'

    A good tutorial on C++ iterators http://www.cprogramming.com/tutorial/stl/iterators.html

    ps. With vectors and ‘maths’ type code, it’s often simpler to just use array index notation

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a bit of headache with some SQL I'm trying to write. Basically,
Wow, I'm having a bit of a headache with Access 2007. I have two
I having a bit of a quandry trying to come up with a good
I'm having bit of a trouble trying to figure out how I would send
Having a bit of problem with some syntax trying to insert HTML after an
Coming from Win32, I am having bit of an issue or a problem trying
im having a bit troubled here. I cannot seem to understand what's the problem
I'm having bit complicated object model that forms a triangle. There is User entity
Having a bit of trouble. I need to find all of the countries that
i'm having a bit of trouble trying to write an sql query. i have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.