03-16-2016 04:17 PM
Hi,
I'm trying to figure out how one would go about averaging values from an N number of 2D arrays, as in all the values of [1,1] averaged, then [1,2] ect to result in a final 2D array of averaged values. All the 2D arrays will be the same size.
Solved! Go to Solution.
03-16-2016 04:35 PM
Can you explain what you mean?
Example in values?
Or if you want get average of one-two-three etc first elements, you can reshape your 2D array to 1D array and then take first 1-2-3... elements.
03-16-2016 04:38 PM
How are the N arrays presented to you....as a 3D array? If so, it sounds like you just need a series of nested for loops to index the values, average them and autoindex them back into another array. Seems fairly straight forward if i understand your requirements.
03-16-2016 04:53 PM
Basically, instead of indexing a row or column, you would be indexing a "page" as they are called. So normally to index a whole row in a 2D array, you leave the column empty and a 1D array of values is returned. WIth a 3D array, you leave the page value blank and specify a row, column and it will return a 1D array of values that span in the Z direction, if you want to call it that.
So for example, these are your 3 2D arrays that are essentially stacked on top of one another.
1 1 1
1 1 1
1 1 1
2 2 2
2 2 2
2 2 2
3 3 3
3 3 3
3 3 3
Index this 3d array with the row and column set to 0 and the page value blank will return 1, 2, 3 (which is the values in the 0,0 position from all 3 arrays).
03-16-2016 05:10 PM
Here is one way to do it. There may be another more efficient method than this....actually I'm fairly positive that is the case....I jus don't know what it is.
03-16-2016 05:32 PM
Here is a one loop method. Add pages and divide by the number of pages.
Lynn
03-16-2016 05:38 PM - edited 03-16-2016 05:40 PM
I would just sum them up in a shift register, e.g. as follows, then divide by the number of iterations:
It would be easy to adapt to other data structures and works equally wel to average 1D or 3D arrays, etc..
How is your original data arranged? If it is a 3D array, replace the while loop with an autoindexing FOR loop and devide after the loop has completed. Modify as needed.*
*EDIT: This is exactly as Lynn suggested. 😄
03-16-2016 06:36 PM
Thank you all for your help. Lynn's VI is perfect.