def array2data(self, data, weights=None, normed=False, binning=1, reBin=None): """ Convert array of data to internal format - Designed for arrays of raw, un-binned data. - If you pass values here from an existing histogram ('weights' is not None and the 'data' param is just bin centers), it is possible to re-bin this histogram using the 'reBin' keyword """ data, bins = np.histogram(data, bins=binning, weights=weights, normed=normed) results = Hist() results.content = data results.bins = bins results.center = tools.midpoints(bins) results.width = tools.widths(bins) results.error = np.sqrt(data) if weights is not None: # numpy digitize to get sumw2 results.error = results.sumw2_1D(xdata=data, values=weights) if reBin is not None: results.Rebin(reBin) if normed: results.normalize() # normalize after re-binning return results