#NEWLINE# def moment( a , moment = 1 , axis = 0 ) : #NEWLINE# #INDENT# '\n    Calculates the nth moment about the mean for a sample.\n\n    Parameters\n    ----------\n    a : array_like\n       data\n    moment : int, optional\n       order of central moment that is returned\n    axis : int or None, optional\n       Axis along which the central moment is computed. Default is 0.\n       If None, compute over the whole array `a`.\n\n    Returns\n    -------\n    n-th central moment : ndarray or float\n       The appropriate moment along the given axis or over all values if axis\n       is None. The denominator for the moment calculation is the number of\n       observations, no degrees of freedom correction is done.\n\n    Notes\n    -----\n    For more details about `moment`, see `stats.moment`.\n\n    ' #NEWLINE# ( a , axis ) = _chk_asarray ( a , axis ) #NEWLINE# if ( moment == 1 ) : #NEWLINE# #INDENT# shape = list ( a . shape ) #NEWLINE# del shape [ axis ] #NEWLINE# if shape : #NEWLINE# #INDENT# return np . zeros ( shape , dtype = float ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return np . float64 ( 0.0 ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# n_list = [ moment ] #NEWLINE# current_n = moment #NEWLINE# while ( current_n > 2 ) : #NEWLINE# #INDENT# if ( current_n % 2 ) : #NEWLINE# #INDENT# current_n = ( ( current_n - 1 ) / 2 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# current_n /= 2 #NEWLINE# #UNINDENT# n_list . append ( current_n ) #NEWLINE# #UNINDENT# a_zero_mean = ( a - ma . expand_dims ( a . mean ( axis ) , axis ) ) #NEWLINE# if ( n_list [ ( - 1 ) ] == 1 ) : #NEWLINE# #INDENT# s = a_zero_mean . copy ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# s = ( a_zero_mean ** 2 ) #NEWLINE# #UNINDENT# for n in n_list [ ( - 2 ) : : ( - 1 ) ] : #NEWLINE# #INDENT# s = ( s ** 2 ) #NEWLINE# if ( n % 2 ) : #NEWLINE# #INDENT# s *= a_zero_mean #NEWLINE# #UNINDENT# #UNINDENT# return s . mean ( n )