def mood(x, y, axis=0):
 x = np.asarray(x, dtype=float)
 y = np.asarray(y, dtype=float)
 if (axis is None):
  x = x.flatten()
  y = y.flatten()
  axis = 0
 res_shape = tuple([x.shape[ax] for ax in range(len(x.shape)) if (ax != axis)])
 if (not (res_shape == tuple([y.shape[ax] for ax in range(len(y.shape)) if (ax != axis)]))):
  raise ValueError('Dimensions of x and y on all axes except `axis` should match')
 n = x.shape[axis]
 m = y.shape[axis]
 N = (m + n)
 if (N < 3):
  raise ValueError('Not enough observations.')
 xy = np.concatenate((x, y), axis=axis)
 if (axis != 0):
  xy = np.rollaxis(xy, axis)
 xy = xy.reshape(xy.shape[0], (-1))
 all_ranks = np.zeros_like(xy)
 for j in range(xy.shape[1]):
  all_ranks[:, j] = stats.rankdata(xy[:, j])
 Ri = all_ranks[:n]
 M = np.sum(((Ri - ((N + 1.0) / 2)) ** 2), axis=0)
 mnM = ((n * ((N * N) - 1.0)) / 12)
 varM = (((((m * n) * (N + 1.0)) * (N + 2)) * (N - 2)) / 180)
 z = ((M - mnM) / sqrt(varM))
 z_pos = (z > 0)
 pval = np.zeros_like(z)
 pval[z_pos] = (2 * distributions.norm.sf(z[z_pos]))
 pval[(~ z_pos)] = (2 * distributions.norm.cdf(z[(~ z_pos)]))
 if (res_shape == ()):
  z = z[0]
  pval = pval[0]
 else:
  z.shape = res_shape
  pval.shape = res_shape
 return (z, pval)

def mood ( x , y , axis = 0 ) : x = np . asarray ( x , dtype = float ) y = np . asarray ( y , dtype = float ) if ( axis is None ) : x = x . flatten ( ) y = y . flatten ( ) axis = 0 res_shape = tuple ( [ x . shape [ ax ] for ax in range ( len ( x . shape ) ) if ( ax != axis ) ] ) if ( not ( res_shape == tuple ( [ y . shape [ ax ] for ax in range ( len ( y . shape ) ) if ( ax != axis ) ] ) ) ) : raise ValueError ( 'Dimensions of x and y on all axes except `axis` should match' ) n = x . shape [ axis ] m = y . shape [ axis ] N = ( m + n ) if ( N < 3 ) : raise ValueError ( 'Not enough observations.' ) xy = np . concatenate ( ( x , y ) , axis = axis ) if ( axis != 0 ) : xy = np . rollaxis ( xy , axis ) xy = xy . reshape ( xy . shape [ 0 ] , ( - 1 ) ) all_ranks = np . zeros_like ( xy ) for j in range ( xy . shape [ 1 ] ) : all_ranks [ : , j ] = stats . rankdata ( xy [ : , j ] ) Ri = all_ranks [ : n ] M = np . sum ( ( ( Ri - ( ( N + 1.0 ) / 2 ) ) ** 2 ) , axis = 0 ) mnM = ( ( n * ( ( N * N ) - 1.0 ) ) / 12 ) varM = ( ( ( ( ( m * n ) * ( N + 1.0 ) ) * ( N + 2 ) ) * ( N - 2 ) ) / 180 ) z = ( ( M - mnM ) / sqrt ( varM ) ) z_pos = ( z > 0 ) pval = np . zeros_like ( z ) pval [ z_pos ] = ( 2 * distributions . norm . sf ( z [ z_pos ] ) ) pval [ ( ~ z_pos ) ] = ( 2 * distributions . norm . cdf ( z [ ( ~ z_pos ) ] ) ) if ( res_shape == ( ) ) : z = z [ 0 ] pval = pval [ 0 ] else : z . shape = res_shape pval . shape = res_shape return ( z , pval )
returns imperative .