0
$\begingroup$

I have a list of lists of the following type

a=[[0.        , 0.03846154, 0.34615385, 0.34615385, 0.42307692,
       0.42307692, 0.53846154, 0.53846154, 0.61538462, 0.61538462,
       0.65384615, 0.65384615, 0.73076923, 0.73076923, 0.76923077,
       0.76923077, 0.80769231, 0.80769231, 0.88461538, 0.88461538,
       0.92307692, 0.92307692, 0.96153846, 0.96153846, 1.        ,
       1.        ], [0.        , 0.03846154, 0.61538462, 0.61538462, 0.69230769,
       0.69230769, 0.73076923, 0.73076923, 0.76923077, 0.76923077,
       0.80769231, 0.80769231, 0.84615385, 0.84615385, 0.88461538,
       0.88461538, 0.92307692, 0.92307692, 0.96153846, 0.96153846,
       1.        , 1.        ], [0.        , 0.03846154, 0.34615385, 0.34615385, 0.42307692,
       0.42307692, 0.61538462, 0.61538462, 0.69230769, 0.69230769,
       0.73076923, 0.73076923, 0.76923077, 0.76923077, 0.80769231,
       0.80769231, 0.84615385, 0.84615385, 0.88461538, 0.88461538,
       0.92307692, 0.92307692, 0.96153846, 0.96153846, 1.        ,
       1.        ], [0.        , 0.03846154, 0.42307692, 0.42307692, 0.57692308,
       0.57692308, 0.76923077, 0.76923077, 0.84615385, 0.84615385,
       0.88461538, 0.88461538, 0.92307692, 0.92307692, 0.96153846,
       0.96153846, 1.        , 1.        ]]

I am trying to compute the mean of this list of list. I am using the following code.

mean_a=[float(sum(col))/len(col) for col in zip(*a)]

But I am getting the following output.

 0.03846154,
 0.43269231,
 0.43269231,
 0.5288461525,
 0.5288461525,
 0.66346154,
 0.66346154,
 0.7307692325,
 0.7307692325,
 0.7692307675,
 0.7692307675,
 0.8173076925,
 0.8173076925,
 0.8557692299999999,
 0.8557692299999999,
 0.89423077,
 0.89423077]

As you can see the output is wrong as the all the last elements of each list is 1 and so the mean should be 1. But I am getting a different mean for the last element.

$\endgroup$
  • $\begingroup$ What should be the dimension, the shape, and the type of the output? $\endgroup$ – Alireza Zolanvari Aug 13 '19 at 7:25
0
$\begingroup$

I think the number of elements in each lists are different. (26 , 22 , 26 , 18)

Zip() function uniformly maps all elements of lists of same sizes. (And that's why the 1's are missing and would round off to 18 elements)

Try maintaining the same number of elements in each List and try to find the mean again.

$\endgroup$
0
$\begingroup$

Please verify whether this statement is correct or not " all the last elements of each list is 1 and so the mean should be 1. But I am getting a different mean for the last element."

Mean is just sum of all elements divided by number of observation.

$\endgroup$
  • $\begingroup$ They are of different lengths as pointed above in the accepted answer. Sorry I missed that part $\endgroup$ – bandit_king28 Aug 13 '19 at 9:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.