How Can I Calculate the Mean of a 2D Array?

Updated Jul 2, 2020

Reported In

Software

  • LabVIEW

Issue Details

I would like to calculate the mean of all elements in a 2D array. I tried to use Mean.vi, but it seems to only accepts a 1D array as its input. Is there a function that would do the same for a 2D array?
 

Solution

Unfortunately, there is not a function that is designed to calculate the mean of a whole 2D array by itself. Therefore, you would need to come up with your own algorithm for that. Below is one way of doing it.
  1. Calculate the sum the 2D array by using Add Array Elements.vi
  2. Calculate the size of the 2D array by using Array Size.vi, which returns the number of elements of each dimension in 1D array
  3. Calculate the total number of elements in the 2D by multiplying the elements, calculated at Step 2., by using Multiply Array Elements.vi
  4. Divide the output of Add Array Elements.vi by that of Multiply Array Elements.vi
 
This technique can extend to 3D arrays and greater dimensions.