MCPcopy Create free account
hub / github.com/EntilZha/PyFunctional / average

Method average

functional/pipeline.py:1025–1041  ·  view source on GitHub ↗

Takes the average of elements in the sequence >>> seq([1, 2]).average() 1.5 >>> seq([('a', 1), ('b', 2)]).average(lambda x: x[1]) :param projection: function to project on the sequence before taking the average :return: average of elements in the s

(self, projection=None)

Source from the content-addressed store, hash-verified

1023 return sum(self)
1024
1025 def average(self, projection=None):
1026 """
1027 Takes the average of elements in the sequence
1028
1029 >>> seq([1, 2]).average()
1030 1.5
1031
1032 >>> seq([('a', 1), ('b', 2)]).average(lambda x: x[1])
1033
1034 :param projection: function to project on the sequence before taking the average
1035 :return: average of elements in the sequence
1036 """
1037 length = self.size()
1038 if projection:
1039 return sum(self.map(projection)) / length
1040 else:
1041 return sum(self) / length
1042
1043 def aggregate(self, *args):
1044 """

Callers 1

test_averageMethod · 0.80

Calls 2

sizeMethod · 0.95
mapMethod · 0.95

Tested by 1

test_averageMethod · 0.64