parameters: (a, axis=None, weights=None, returned = 0)
docstring: average(a, axis=None, weights=None)
         Computes average along indicated axis.
         If axis is None, average over the entire array
         Inputs can be integer or floating types; result is of type float.
  
         If weights are given, result is sum(a*weights,axis=0)/(sum(weights,axis=0)*1.0)
         weights must have a's shape or be the 1-d with length the size
         of a in the given axis.
  
         If returned, return a tuple: the result and the sum of the weights
         or count of values. Results will have the same shape.
  
         masked values in the weights will be set to 0.0
docstring_summary: average(a, axis=None, weights=None)
         Computes average along indicated axis.
         If axis is None, average over the entire array
         Inputs can be integer or floating types; result is of type float.
docstring_tokens: average ( a axis = None weights = None ) Computes average along indicated axis . If axis is None average over the entire array Inputs can be integer or floating types ; result is of type float .
function: def new_average (a, axis=None, weights=None, returned = 0):
      """average(a, axis=None, weights=None)
         Computes average along indicated axis.
         If axis is None, average over the entire array
         Inputs can be integer or floating types; result is of type float.
  
         If weights are given, result is sum(a*weights,axis=0)/(sum(weights,axis=0)*1.0)
         weights must have a's shape or be the 1-d with length the size
         of a in the given axis.
  
         If returned, return a tuple: the result and the sum of the weights
         or count of values. Results will have the same shape.
  
         masked values in the weights will be set to 0.0
      """
      a = masked_array(a)
      mask = a.mask
      ash = a.shape
      if ash == ():
          ash = (1,)
      if axis is None:
          if mask is nomask:
              if weights is None:
                  n = add.reduce(a.raw_data().ravel())
                  d = reduce(lambda x, y: x * y, ash, 1.0)
              else:
                  w = filled(weights, 0.0).ravel()
                  n = umath.add.reduce(a.raw_data().ravel() * w)
                  d = umath.add.reduce(w)
                  del w
          else:
              if weights is None:
                  n = add.reduce(a.ravel())
                  w = fromnumeric.choose(mask, (1.0, 0.0)).ravel()
                  d = umath.add.reduce(w)
                  del w
              else:
                  w = array(filled(weights, 0.0), float, mask=mask).ravel()
                  n = add.reduce(a.ravel() * w)
                  d = add.reduce(w)
                  del w
      else:
          if mask is nomask:
              if weights is None:
                  d = ash[axis] * 1.0
                  n = umath.add.reduce(a.raw_data(), axis)
              else:
                  w = filled(weights, 0.0)
                  wsh = w.shape
                  if wsh == ():
                      wsh = (1,)
                  if wsh == ash:
                      w = numeric.array(w, float, copy=0)
                      n = add.reduce(a*w, axis)
                      d = add.reduce(w, axis)
                      del w
                  elif wsh == (ash[axis],):
                      r = [newaxis]*len(ash)
                      r[axis] = slice(None, None, 1)
                      w = eval ("w["+ repr(tuple(r)) + "] * ones(ash, float)")
                      n = add.reduce(a*w, axis)
                      d = add.reduce(w, axis)
                      del w, r
                  else:
                      raise ValueError, 'average: weights wrong shape.'
          else:
              if weights is None:
                  n = add.reduce(a, axis)
                  w = numeric.choose(mask, (1.0, 0.0))
                  d = umath.add.reduce(w, axis)
                  del w
              else:
                  w = filled(weights, 0.0)
                  wsh = w.shape
                  if wsh == ():
                      wsh = (1,)
                  if wsh == ash:
                      w = array(w, float, mask=mask, copy=0)
                      n = add.reduce(a*w, axis)
                      d = add.reduce(w, axis)
                  elif wsh == (ash[axis],):
                      r = [newaxis]*len(ash)
                      r[axis] = slice(None, None, 1)
                      w = eval ("w["+ repr(tuple(r)) + "] * masked_array(ones(ash, float), mask)")
                      n = add.reduce(a*w, axis)
                      d = add.reduce(w, axis)
                  else:
                      raise ValueError, 'average: weights wrong shape.'
                  del w
      #print n, d, repr(mask), repr(weights)
      if n is masked or d is masked: return masked
      result = divide (n, d)
      del n
  
      if isinstance(result, MaskedArray):
          result.unmask()
          if returned:
              if not isinstance(d, MaskedArray):
                  d = masked_array(d)
              if not d.shape == result.shape:
                  d = ones(result.shape, float) * d
              d.unmask()
      if returned:
          return result, d
      else:
          return result
function_tokens: def new_average ( a , axis = None , weights = None , returned = 0 ) : a = masked_array ( a ) mask = a . mask ash = a . shape if ash == ( ) : ash = ( 1 , ) if axis is None : if mask is nomask : if weights is None : n = add . reduce ( a . raw_data ( ) . ravel ( ) ) d = reduce ( lambda x , y : x * y , ash , 1.0 ) else : w = filled ( weights , 0.0 ) . ravel ( ) n = umath . add . reduce ( a . raw_data ( ) . ravel ( ) * w ) d = umath . add . reduce ( w ) del w else : if weights is None : n = add . reduce ( a . ravel ( ) ) w = fromnumeric . choose ( mask , ( 1.0 , 0.0 ) ) . ravel ( ) d = umath . add . reduce ( w ) del w else : w = array ( filled ( weights , 0.0 ) , float , mask = mask ) . ravel ( ) n = add . reduce ( a . ravel ( ) * w ) d = add . reduce ( w ) del w else : if mask is nomask : if weights is None : d = ash [ axis ] * 1.0 n = umath . add . reduce ( a . raw_data ( ) , axis ) else : w = filled ( weights , 0.0 ) wsh = w . shape if wsh == ( ) : wsh = ( 1 , ) if wsh == ash : w = numeric . array ( w , float , copy = 0 ) n = add . reduce ( a * w , axis ) d = add . reduce ( w , axis ) del w elif wsh == ( ash [ axis ] , ) : r = [ newaxis ] * len ( ash ) r [ axis ] = slice ( None , None , 1 ) w = eval ( "w[" + repr ( tuple ( r ) ) + "] * ones(ash, float)" ) n = add . reduce ( a * w , axis ) d = add . reduce ( w , axis ) del w , r else : raise ValueError , 'average: weights wrong shape.' else : if weights is None : n = add . reduce ( a , axis ) w = numeric . choose ( mask , ( 1.0 , 0.0 ) ) d = umath . add . reduce ( w , axis ) del w else : w = filled ( weights , 0.0 ) wsh = w . shape if wsh == ( ) : wsh = ( 1 , ) if wsh == ash : w = array ( w , float , mask = mask , copy = 0 ) n = add . reduce ( a * w , axis ) d = add . reduce ( w , axis ) elif wsh == ( ash [ axis ] , ) : r = [ newaxis ] * len ( ash ) r [ axis ] = slice ( None , None , 1 ) w = eval ( "w[" + repr ( tuple ( r ) ) + "] * masked_array(ones(ash, float), mask)" ) n = add . reduce ( a * w , axis ) d = add . reduce ( w , axis ) else : raise ValueError , 'average: weights wrong shape.' del w #print n, d, repr(mask), repr(weights) if n is masked or d is masked : return masked result = divide ( n , d ) del n if isinstance ( result , MaskedArray ) : result . unmask ( ) if returned : if not isinstance ( d , MaskedArray ) : d = masked_array ( d ) if not d . shape == result . shape : d = ones ( result . shape , float ) * d d . unmask ( ) if returned : return result , d else : return result