Problem: You have over-written the function mean()
with a variable called mean
(which is a float), and these cannot be called as a function.¶
Solution: 1: Use a different name for our mean¶
from numpy import mean
a = [1.0, 2.0, 3.0, 2.0, 1.0]
meanval = sum(a)/len(a)
print(meanval)
b = [2.0, 5.0, 7.0]
print(mean(b))
1.8
4.666666666666667
Solution: 2: import numpy as np and use np.mean
¶
import numpy as np
a = [1.0, 2.0, 3.0, 2.0, 1.0]
mean = sum(a)/len(a)
print(mean)
b = [2.0, 5.0, 7.0]
print(np.mean(b))
1.8
4.666666666666667