When trying to calculate the sample mean of some data, based on the number of samples (first for 1 sample, then for 2 and so on...) I encounter this problem:
/usr/local/lib/python3.6/dist-packages/numpy/core/fromnumeric.py:3584: RuntimeWarning: Degrees of freedom <= 0 for slice
**kwargs)
/usr/local/lib/python3.6/dist-packages/numpy/core/_methods.py:209: RuntimeWarning: invalid value encountered in double_scalars
ret = ret.dtype.type(ret / rcount)
while using numpy function "np.var()" on a data array.
my only function is this one:
def estimate_var(lam, n):
np.random.seed(7)
data = np.random.exponential(scale=1/lam, size=n)
new_data = [np.var(data[:index + 1], ddof=1) for index in range(len(data))]
return new_data
(THE 4th line causes the problem)