Calculate an array-average of multiple arrays in a dictionary
I have a dictionary of arrays. All arrays have exactly the same dimensions. I would like to get an array that represents the average of all the arrays in the dictionary. Is there an easy way to do this?
Let me give you a more explicit example of what I need. My dictionary is as follows:
mydictionary=[('file1', array([1,1,1,1])), ('file2', array([2,2,2,2])), ('file3', array([4,4,4,4]))]
I would like to get an average-array like the following:
averagearray=([3.5,3.5,3.5,3.5])
That's to say that the only average that I need to do is across the arrays of the dictionary, not within each array. Is there any built-in function that I can use or do I have to do the average by myself? If I have to get an array with the standard deviation, do I have to calculate that by hand too?开发者_运维百科
pseudo code:
decimal avgArray;
for i=0 to dictionary.length
avgArray(i) = AVG(dictionary(i))
end for
decimal function AVG(array)
decimal sum=0;
for i =0 to array.length
sum +=array(i)
end for
return sum/array.lenth
end function
精彩评论