histogram1d
- sherpa.utils.histogram1d(x, x_lo, x_hi)[source] [edit on github]
Create a 1D histogram from a sequence of samples.
See the
numpy.histogram
routine for a version with more options.Changed in version 4.15.0: The x_lo and x_hi arguments are no-longer changed (sorted) by this routine.
- Parameters:
x (sequence of numbers) – The array of samples
x_lo (sequence of numbers) – The lower-edges of each bin.
x_hi (sequence of numbers) – The upper-edges of each bin, which must be the same size as
x_lo
.
- Returns:
y – The number of samples in each histogram bin defined by the
x_lo
andx_hi
arrays.- Return type:
NumPy array
Examples
A simple example, calculating the histogram of 1000 values randomly distributed over [0, 1).
>>> x = np.random.random(1000) >>> edges = np.arange(0, 1.1, 0.1) >>> xlo = edges[:-1] >>> xhi = edges[1:] >>> y = histogram1d(x, xlo, xhi)
Given a list of samples, bin them up so that they can be used as the dependent axis (the value to be fitted) in a Sherpa data set:
>>> dataspace1d(1, 10, 1) >>> lo, hi = get_indep() >>> n = histogram1d([2, 3, 2, 8, 5, 2], lo, hi) >>> set_dep(n)