Error while trying to calculate average of an array

I am trying to calculate the average of an array. I cannot figure out why I am getting this error.

error: request for member 'Sum' in 'pixels', which is of non-class type 'float [64]'
error: request for member 'Length' in 'pixels', which is of non-class type 'float [64]'

  int sum = pixels.Sum;
  int AVGTEMP = sum / pixels.Length;
  float sum = 0;
  int length = size(pixels)/size(pixels[0]);
  for (int j=0; j<length; j++) sum += pixels[j];
  float AVGTEMP = sum / length;
1 Like

You need to loop over your C-like float pixels[64]; array rather than treating the array like a class with methods.

If pixels is an array of float, then your code snippet makes no sense at all.

Why?

Because arrays in C don't have methods. They aren't classes.

@fader402
Arrays in C doesn't have a dedicated method Sum.

Instead of this you have to iterate array elements one by one in a loop and calculate it sum by addition.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.