def t_one_observation(x, sample, tails='two-sided', exp_diff=0):
 try:
  sample_mean = mean(sample)
  sample_std = std(sample, ddof=1)
  if (sample_std == 0):
   return (nan, nan)
  else:
   n = len(sample)
   t = ((((x - sample_mean) - exp_diff) / sample_std) / sqrt(((n + 1) / n)))
   prob = tprob(t, (n - 1), tails)
   return (float(t), prob)
 except (ZeroDivisionError, ValueError, AttributeError, TypeError, FloatingPointError):
  return (nan, nan)

def t_one_observation ( x , sample , tails = 'two-sided' , exp_diff = 0 ) : try : sample_mean = mean ( sample ) sample_std = std ( sample , ddof = 1 ) if ( sample_std == 0 ) : return ( nan , nan ) else : n = len ( sample ) t = ( ( ( ( x - sample_mean ) - exp_diff ) / sample_std ) / sqrt ( ( ( n + 1 ) / n ) ) ) prob = tprob ( t , ( n - 1 ) , tails ) return ( float ( t ) , prob ) except ( ZeroDivisionError , ValueError , AttributeError , TypeError , FloatingPointError ) : return ( nan , nan )
returns t-test for significance of single observation versus a sample .