I want to write this code as pythonic. My real array much bigger than this example.
( 5+10+20+3+2 ) / 5
print(np.mean(array,key=lambda x:x[1])
Just find the average using sum and number of elements of the list.
array = [('a', 5) , ('b', 10), ('c', 20), ('d', 3), ('e', 2)] avg = float(sum(value[1] for value in array)) / float(len(array)) print(avg) #8.0