Aug-01-2017, 12:49 AM
(This post was last modified: Aug-01-2017, 12:50 AM by rakhmadiev.)
Hello,
I have a list of lists and I need to calculate the mean across the dimension. The problem is that the sublists are all of different length. For example:
array=[[5,2,1],[2,1],[3,4,2,1]]
So in this case I am looking for the following result:
mean=[3.333, 2.333, 1.5, 1] #[(5+2+2)/3, (2+1+4)/3, (1+2)/2, 1/1]
I found that this can be done with numpy.ma.mean. As far as I understood I have to combine all my sublists into one masked array.
But I cannot figure out how to do it, taking into account that the number of sublists in an array and the length of sublists is always different.
Thanks in advance
I have a list of lists and I need to calculate the mean across the dimension. The problem is that the sublists are all of different length. For example:
array=[[5,2,1],[2,1],[3,4,2,1]]
So in this case I am looking for the following result:
mean=[3.333, 2.333, 1.5, 1] #[(5+2+2)/3, (2+1+4)/3, (1+2)/2, 1/1]
I found that this can be done with numpy.ma.mean. As far as I understood I have to combine all my sublists into one masked array.
But I cannot figure out how to do it, taking into account that the number of sublists in an array and the length of sublists is always different.
Thanks in advance