histogram1d

sherpa.utils.histogram1d(x, x_lo, x_hi)[source]

Create a 1D histogram from a binned grid (x_lo, xhi) and array of samples (x).

See the numpy.histogram routine for a version with more options.

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 and x_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 (vals), bin them up so that they can be used as the dependent axis (the value to be fitted) in a Sherpa data set:

>>> dataspace1d(0.1, 10, 0.1)
>>> (lo, hi) = get_indep()
>>> n = histogram1d(vals, lo, hi)
>>> set_dep(n)