1 | initial version |
Here is how you would do it, assuming A
and B
are NumPy arrays:
import matplotlib.pyplot as plt
mean = A.mean()
standard_deviation = A.std()
plt.hist(B)
plt.savefig('histogram.png')
Unfortunately Sage does not yet have good histogram functionality; however, it does have mean and standard deviation, with the benefit that you can get exact output:
sage: std(range(10))
sqrt(55/6)
2 | No.2 Revision |
Here is how you would do it, assuming A
and B
are NumPy arrays:
import matplotlib.pyplot as plt
mean = A.mean()
standard_deviation = A.std()
plt.hist(B)
plt.savefig('histogram.png')
Unfortunately Sage does not yet have good histogram functionality; however, it does have mean and standard deviation, with the benefit that you can get exact output:
sage: std(range(10))
sqrt(55/6)
EDIT: Here's a way to take the frequencies into account:
def mean2(data, freq):
return sum(map(prod, zip(data, freq))) / sum(freq)
def std2(data, freq):
data2 = []
for index, item in enumerate(data):
data2.extend([item] * freq[index])
return std(data2)
3 | No.3 Revision |
Here is how you would do it, assuming A
and B
are NumPy arrays:
import matplotlib.pyplot as plt
mean = A.mean()
standard_deviation = A.std()
plt.hist(B)
plt.savefig('histogram.png')
Unfortunately Sage does not yet have good histogram functionality; however, it does have mean and standard deviation, with the benefit that you can get exact output:
sage: std(range(10))
sqrt(55/6)
EDIT: Here's a way to take the (integer) frequencies into account:
def mean2(data, freq):
return sum(map(prod, zip(data, freq))) / sum(freq)
def std2(data, freq):
data2 = []
for index, item in enumerate(data):
data2.extend([item] * freq[index])
return std(data2)