BinnedData#

class zfit.data.BinnedData(*, holder)[source]#

Bases: ZfitBinnedData

Create a binned data object from a BinnedHolder.

Prefer to use the constructors from_* of BinnedData like from_hist(), from_tensor() or from_unbinned().

Parameters

holder

classmethod from_tensor(space, values, variances=None)[source]#

Create a binned dataset defined in space where values are considered to be the counts.

Parameters
  • space (ZfitSpace) – ​Binned space of the data. The space is used to define the binning and the limits of the data.​

  • values (znp.array) – ​Corresponds to the counts of the histogram. Follows the definition of the Unified Histogram Interface (UHI).​

  • variances (znp.array | None) –

    ​Corresponds to the uncertainties of the histogram. If True, the uncertainties are created assuming that values have been drawn from a Poisson distribution. Follows the definition of the Unified Histogram Interface (UHI).​

Return type

BinnedData

classmethod from_unbinned(space, data)[source]#

Convert an unbinned dataset to a binned dataset.

Parameters
  • space (ZfitSpace) – ​Binned space of the data. The space is used to define the binning and the limits of the data.​

  • data (ZfitData) – Unbinned data to be converted to binned data

Returns

The binned data

Return type

ZfitBinnedData

classmethod from_hist(h)[source]#

Create a binned dataset from a hist histogram.

A histogram (following the UHI definition) with named axes.

Parameters

h (NamedHist) – A NamedHist. The axes will be used as the binning in zfit.

Return type

BinnedData

with_obs(obs)[source]#

Return a subset of the data in the ordering of obs.

Parameters

obs (Union[str, Iterable[str], zfit.Space]) – Which obs to return

Return type

BinnedData

to_hist()[source]#

Convert the binned data to a NamedHist.

While a binned data object can be used inside zfit (PDFs,…), it lacks many convenience features that the hist library offers, such as plots.

Return type

Hist

values()[source]#

Values of the histogram as an ndim array.

Compared to hist, zfit does not make a difference between a view and a copy; tensors are immutable. This distinction is made in the traced function by the compilation backend.

Return type

array

Returns

Tensor of shape (nbins0, nbins1, …) with nbins the number of bins in each observable.

variances()[source]#

Variances, if available, of the histogram as an ndim array.

Compared to hist, zfit does not make a difference between a view and a copy; tensors are immutable. This distinction is made in the traced function by the compilation backend.

Return type

None | znp.array

Returns

Tensor of shape (nbins0, nbins1, …) with nbins the number of bins in each observable.

counts()[source]#

Effective counts of the histogram as a ndim array.

Compared to hist, zfit does not make a difference between a view and a copy; tensors are immutable. This distinction is made in the traced function by the compilation backend.

Returns

Tensor of shape (nbins0, nbins1, …) with nbins the number of bins in each observable.

to_unbinned()[source]#

Use the bincenters as unbinned data with values as counts.

Returns

Unbinned data

Return type

ZfitData