python average of two lists by row

37

python average of two lists by row -

# Basic syntax:
[(a + b)/2 for a, b in zip(list_1, list_2)]

# Example usage:
list_1 = [1, 2, 3]
list_2 = [4, 5, 6]
[(a + b)/2 for a, b in zip(list_1, list_2)]
--> [2.5, 3.5, 4.5]

average of two lists python -

>>> import numpy as np
>>> data = np.array([[1, 2, 3], [5, 6, 7]])
>>> np.average(data, axis=0)
array([ 3.,  4.,  5.])

Comments

Submit
0 Comments