Returns d-1 dimensional histogram of (estimated) std value along axis
        NB this is very different from just std of the histogram values (which describe bin counts)
333993
def std(self, axis):
        
        def weighted_std(values, weights, axis):
            # Stolen from http://stackoverflow.com/questions/2413522
            average = np.average(values, weights=weights, axis=axis)
            average = average[self._simsalabim_slice(axis)]
            variance = np.average((values-average)**2, weights=weights, axis=axis)
            return np.sqrt(variance)
        
        axis = self.get_axis_number(axis)
        std_hist = weighted_std(self.all_axis_bin_centers(axis),
                                weights=self.histogram, axis=axis)
        if self.dimensions == 2:
            new_hist = Hist1d
        else:
            new_hist = Histdd
        return new_hist.from_histogram(histogram=std_hist,
                                       bin_edges=itemgetter(*self.other_axes(axis))(self.bin_edges),
                                       axis_names=self.axis_names_without(axis))
370120
def _get_delta(self, stds, dists):
        
        delta = np.maximum((0.1-0.001*dists.repi), np.zeros_like(dists.repi))
        return delta
486919
def std(self, bessel_correction=True):
        """"""
        if bessel_correction:
            n = self.n
            bc = n / (n - 1)
        else:
            bc = 1
        return np.sqrt(np.average((self.bin_centers - self.mean) ** 2, weights=self.histogram)) * bc
655358
def central_likelihood(self, axis):
        """"""
        result = self.cumulative_density(axis)
        result.histogram = 1 - 2 * np.abs(result.histogram - 0.5)
        return result
17997
def get_bin_indices(self, values):
        """"""
        return tuple([self.get_axis_bin_index(values[ax_i], ax_i)
                      for ax_i in range(self.dimensions)])
926545
def normalize(self, axis):
        """"""
        axis = self.get_axis_number(axis)
        sum_along_axis = np.sum(self.histogram, axis=axis)
        # Don't do anything for subspaces without any entries -- this avoids nans everywhere
        sum_along_axis[sum_along_axis == 0] = 1
        hist = self.histogram / sum_along_axis[self._simsalabim_slice(axis)]
        return Histdd.from_histogram(hist,
                                     bin_edges=self.bin_edges,
                                     axis_names=self.axis_names)
225175
def intensityDistributionSTE(self, bins=10, range=None):
        '''
        
        '''
        v = np.abs(self._last_diff[self.mask_STE])
        return np.histogram(v, bins, range)
144579
def uniform_binned(self, name=None):
        
        if self.GetDimension() == 1:
            new_hist = Hist(
                self.GetNbinsX(), 0, self.GetNbinsX(),
                name=name, type=self.TYPE)
        elif self.GetDimension() == 2:
            new_hist = Hist2D(
                self.GetNbinsX(), 0, self.GetNbinsX(),
                self.GetNbinsY(), 0, self.GetNbinsY(),
                name=name, type=self.TYPE)
        else:
            new_hist = Hist3D(
                self.GetNbinsX(), 0, self.GetNbinsX(),
                self.GetNbinsY(), 0, self.GetNbinsY(),
                self.GetNbinsZ(), 0, self.GetNbinsZ(),
                name=name, type=self.TYPE)
        # copy over the bin contents and errors
        for outbin, inbin in zip(new_hist.bins(), self.bins()):
            outbin.value = inbin.value
            outbin.error = inbin.error
        new_hist.decorate(self)
        new_hist.entries = self.entries
        return new_hist
77585
def rgb(self):
        
        coords = tuple(self.dimension_values(d, expanded=False)
                       for d in self.kdims)
        data = [self.dimension_values(d, flat=False)
                for d in self.vdims]

        hsv = self.hsv_to_rgb(*data[:3])
        if len(self.vdims) == 4:
            hsv += (data[3],)

        params = util.get_param_values(self)
        del params['vdims']
        return RGB(coords+hsv, bounds=self.bounds,
                   xdensity=self.xdensity, ydensity=self.ydensity,
                   **params)
1247329
def get_distbins(start=100, bins=2500, ratio=1.01):
    
    b = np.ones(bins, dtype="float64")
    b[0] = 100
    for i in range(1, bins):
        b[i] = b[i - 1] * ratio
    bins = np.around(b).astype(dtype="int")
    binsizes = np.diff(bins)
    return bins, binsizes
1257559
def histogram(self, cycle_data, bins=10):
        
        values, edges = np.histogram(cycle_data['cycle_time'].astype('timedelta64[D]').dropna(), bins=bins)

        index = []
        for i, v in enumerate(edges):
            if i == 0:
                continue
            index.append("%.01f to %.01f" % (edges[i - 1], edges[i],))

        return pd.Series(values, name="Items", index=index)
1225394
def _process_hist(self, hist):
        
        edges, hvals, widths, lims, isdatetime = super(SideHistogramPlot, self)._process_hist(hist)
        offset = self.offset * lims[3]
        hvals *= 1-self.offset
        hvals += offset
        lims = lims[0:3] + (lims[3] + offset,)
        return edges, hvals, widths, lims, isdatetime
960004
def mean_std(fractions):
    
    n = fractions.shape[0]
    if n == 1:  # avoid warnings when computing the stddev
        return fractions[0], numpy.ones_like(fractions[0]) * numpy.nan
    return numpy.mean(fractions, axis=0), numpy.std(fractions, axis=0, ddof=1)
750164
def histogram(series, **kwargs):
    
    imgdata = BytesIO()
    plot = _plot_histogram(series, **kwargs)
    plot.figure.subplots_adjust(left=0.15, right=0.95, top=0.9, bottom=0.1, wspace=0, hspace=0)
    plot.figure.savefig(imgdata)
    imgdata.seek(0)
    result_string = 'data:image/png;base64,' + quote(base64.b64encode(imgdata.getvalue()))
    # TODO Think about writing this to disk instead of caching them in strings
    plt.close(plot.figure)
    return result_string
792937
def zscore(bars, window=20, stds=1, col='close'):
    
    std = numpy_rolling_std(bars[col], window)
    mean = numpy_rolling_mean(bars[col], window)
    return (bars[col] - mean) / (std * stds)
446961
def within_n_std(df, n=3):
    
    means = df.mean()
    stds = df.std()
    inliers = (np.abs(df[means.index] - means) < n * stds)
    if not np.all(inliers):
        msg = generic.bad_locations(~inliers)
        raise AssertionError(msg)
    return df
860024
def normalized(self):
        
        total = self.total()
        result = Histogram()
        for value, count in iteritems(self):
            try:
                result[value] = count / float(total)
            except UnorderableElements as e:
                result = Histogram.from_dict(dict(result), key=hash)
                result[value] = count / float(total)
        return result