def _prf_divide(numerator, denominator, metric, modifier, average, warn_for):
 result = (numerator / denominator)
 mask = (denominator == 0.0)
 if (not np.any(mask)):
  return result
 result[mask] = 0.0
 axis0 = 'sample'
 axis1 = 'label'
 if (average == 'samples'):
  (axis0, axis1) = (axis1, axis0)
 if ((metric in warn_for) and ('f-score' in warn_for)):
  msg_start = '{0} and F-score are'.format(metric.title())
 elif (metric in warn_for):
  msg_start = '{0} is'.format(metric.title())
 elif ('f-score' in warn_for):
  msg_start = 'F-score is'
 else:
  return result
 msg = '{0} ill-defined and being set to 0.0 {{0}} no {1} {2}s.'.format(msg_start, modifier, axis0)
 if (len(mask) == 1):
  msg = msg.format('due to')
 else:
  msg = msg.format('in {0}s with'.format(axis1))
 warnings.warn(msg, UndefinedMetricWarning, stacklevel=2)
 return result

def _prf_divide ( numerator , denominator , metric , modifier , average , warn_for ) : result = ( numerator / denominator ) mask = ( denominator == 0.0 ) if ( not np . any ( mask ) ) : return result result [ mask ] = 0.0 axis0 = 'sample' axis1 = 'label' if ( average == 'samples' ) : ( axis0 , axis1 ) = ( axis1 , axis0 ) if ( ( metric in warn_for ) and ( 'f-score' in warn_for ) ) : msg_start = '{0} and F-score are' . format ( metric . title ( ) ) elif ( metric in warn_for ) : msg_start = '{0} is' . format ( metric . title ( ) ) elif ( 'f-score' in warn_for ) : msg_start = 'F-score is' else : return result msg = '{0} ill-defined and being set to 0.0 {{0}} no {1} {2}s.' . format ( msg_start , modifier , axis0 ) if ( len ( mask ) == 1 ) : msg = msg . format ( 'due to' ) else : msg = msg . format ( 'in {0}s with' . format ( axis1 ) ) warnings . warn ( msg , UndefinedMetricWarning , stacklevel = 2 ) return result
performs division and handles divide-by-zero .