def _medcouple_1d(y):
 y = np.squeeze(np.asarray(y))
 if (y.ndim != 1):
  raise ValueError('y must be squeezable to a 1-d array')
 y = np.sort(y)
 n = y.shape[0]
 if ((n % 2) == 0):
  mf = ((y[((n // 2) - 1)] + y[(n // 2)]) / 2)
 else:
  mf = y[((n - 1) // 2)]
 z = (y - mf)
 lower = z[(z <= 0.0)]
 upper = z[(z >= 0.0)]
 upper = upper[:, None]
 standardization = (upper - lower)
 is_zero = np.logical_and((lower == 0.0), (upper == 0.0))
 standardization[is_zero] = np.inf
 spread = (upper + lower)
 return np.median((spread / standardization))

def _medcouple_1d ( y ) : y = np . squeeze ( np . asarray ( y ) ) if ( y . ndim != 1 ) : raise ValueError ( 'y must be squeezable to a 1-d array' ) y = np . sort ( y ) n = y . shape [ 0 ] if ( ( n % 2 ) == 0 ) : mf = ( ( y [ ( ( n // 2 ) - 1 ) ] + y [ ( n // 2 ) ] ) / 2 ) else : mf = y [ ( ( n - 1 ) // 2 ) ] z = ( y - mf ) lower = z [ ( z <= 0.0 ) ] upper = z [ ( z >= 0.0 ) ] upper = upper [ : , None ] standardization = ( upper - lower ) is_zero = np . logical_and ( ( lower == 0.0 ) , ( upper == 0.0 ) ) standardization [ is_zero ] = np . inf spread = ( upper + lower ) return np . median ( ( spread / standardization ) )
calculates the medcouple robust measure of skew .