def simple_moving_average ( x , n = 10 ) : if x . ndim > 1 and len ( x [ 0 ] ) > 1 : x = np . average ( x , axis = 1 ) a = np . ones ( n ) / float ( n ) return np . convolve ( x , a , 'valid' )
moving average predictionn using python on sales data aset
Calculate simple moving average
def simple_moving_average(x, n=10):
    """
    Calculate simple moving average

    Parameters
    ----------
    x : ndarray
        A numpy array
    n : integer
        The number of sample points used to make average

    Returns
    -------
    ndarray
        A 1 x n numpy array instance
    """
    if x.ndim > 1 and len(x[0]) > 1:
        x = np.average(x, axis=1)
    a = np.ones(n) / float(n)
    return np.convolve(x, a, 'valid')