Output: standard deviation of array
510473
private double calcSD(double[] arr, double mean) {
        double sd = 0;
        for (double resid : arr) {
            sd += Math.pow(resid - mean, 2);
        }
        sd = Math.sqrt(sd/arr.length);
        return sd;
    }
657416
def stdev(data, xbar=None):
    
    var = variance(data, xbar)
    try:
        return var.sqrt()
    except AttributeError:
        return math.sqrt(var)
115486
private double calcMean(double[] arr) {
        double mean = 0;
        for (double resid : arr) {
            mean += resid;
        }
        mean /= arr.length;
        return mean;
    }
248809
def _get_stddevs(self, C, C_PGA, pga1100, rup, sites, stddev_types):
        
        std_intra = self._compute_intra_event_std(C, C_PGA, pga1100, rup.mag,
                                                  sites.vs30,
                                                  sites.vs30measured)
        std_inter = self._compute_inter_event_std(C, C_PGA, pga1100, rup.mag,
                                                  sites.vs30)
        stddevs = []
        for stddev_type in stddev_types:
            assert stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES
            if stddev_type == const.StdDev.TOTAL:
                stddevs.append(np.sqrt(std_intra ** 2 + std_inter ** 2))
            elif stddev_type == const.StdDev.INTRA_EVENT:
                stddevs.append(std_intra)
            elif stddev_type == const.StdDev.INTER_EVENT:
                stddevs.append(std_inter)
        return stddevs
521183
def variance
      μ = mean
      reduce(0) { |m, i| m + (i - μ).square } / (length - 1)
    end
1179223
function variance( out, x ) {
	var len = x.length,
		i;
	if ( out.length !== len ) {
		throw new Error( 'variance()::invalid input arguments. Input and output matrices must be the same length.' );
	}
	for ( i = 0; i < len; i++ ) {
		out.data[ i ] = VARIANCE( x.data[ i ] );
	}
	return out;
}
446669
def _get_stddevs(self, C, stddev_types, rup, imt, num_sites):
        
        stddevs = []
        for stddev_type in stddev_types:
            sigma_mean = self._compute_standard_dev(rup, imt, C)
            sigma_tot = np.sqrt((sigma_mean ** 2) + (C['SigmaReg'] ** 2))
            sigma_tot = np.log10(np.exp(sigma_tot))
            stddevs.append(sigma_tot + np.zeros(num_sites))
        return stddevs
25822
private static Stats calcStats(List<Double> nums) {
    double sum = 0.0, mean = 0.0, variance = 0.0, stdDev = 0.0;
    for (Double d : nums) {
      sum += d.doubleValue();
    }
    if (nums.size() > 0) {
      mean = sum / nums.size();
    }

    sum = 0.0;
    for (Double d : nums) {
      sum += (d.doubleValue() - mean) * (d.doubleValue() - mean);
    }
    if (nums.size() > 0) {
      variance = sum / nums.size();
    }

    stdDev = Math.sqrt(variance);
    return new Stats(mean, variance, stdDev);
  }
1070657
def stddev(values, meanval=None):  #from AI: A Modern Appproach
    """"""
    if meanval == None: meanval = mean(values)
    return math.sqrt( sum([(x - meanval)**2 for x in values]) / (len(values)-1) )
487021
def _get_stddevs(self, C, stddev_types, num_sites):
        
        stddevs = []
        for stddev_type in stddev_types:
            assert stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES
            stddevs.append(np.log(10 ** C['sigma']) + np.zeros(num_sites))

        return stddevs
980315
private void standardize(double[] values) {
        double mean = calculateMean(values);
        double stdDev = calculateStandardDeviation(values, mean);

        /*
         * If standard deviation is 0, all values of the metric are
         * identical. Return vector of 0s.
         */
        if (stdDev == 0.0) {
            for (int i = 0; i < values.length; i++) {
                values[i] = 0.0;
            }
            return;
        };

        for (int i = 0; i < values.length; i++) {
            double standardizedValue = (values[i] - mean) / stdDev;
            values[i] = standardizedValue;
        }
    }
199614
def average(arr):
  
  if len(arr) == 0:
    sys.stderr.write("ERROR: no content in array to take average\n")
    sys.exit()
  if len(arr) == 1:  return arr[0]
  return float(sum(arr))/float(len(arr))
393032
def samplevar(inlist):
    
    n = len(inlist)
    mn = mean(inlist)
    deviations = []
    for item in inlist:
        deviations.append(item - mn)
    return ss(deviations) / float(n)
575790
def variance(self) -> Optional[float]:  #, ddof: int = 0) -> float:
        
        # TODO: Add DOF
        # http://stats.stackexchange.com/questions/6534/how-do-i-calculate-a-weighted-standard-deviation-in-excel
        if self._stats:
            if self.total > 0:
                return (self._stats["sum2"] - self._stats["sum"] ** 2 / self.total) / self.total
            else:
                return np.nan
        else:
            return None
201270
def standard_deviation(numbers):
    """"""
    numbers = list(numbers)
    if not numbers:
        return 0
    mean = sum(numbers) / len(numbers)
    return (sum((n - mean) ** 2 for n in numbers) /
            len(numbers)) ** .5
469422
def _get_stddevs(self, coeffs, stddev_types, num_sites):
        
        stddevs = []
        for stddev_type in stddev_types:
            assert stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES
            stddevs.append(coeffs['sigma'] + np.zeros(num_sites))
        return np.array(stddevs)
65289
def variance(arr):
  
  avg = average(arr)
  return sum([(float(x)-avg)**2 for x in arr])/float(len(arr)-1)