centers_to_edges#
- atompy.centers_to_edges(centers, lower=None, upper=None)[source]#
Work out bin edges from bin centers.
If the bins don’t have constant size, at least one limit has to be provided, from which the edges can be determined.
Attention
If centers are not the centers of all bins, or if lower or upper are not indeed the lower or upper edge, centers_to_edges will silently produce nonsense.
- Parameters:
- centersarray_like, shape(n)
centers of the bins
- lower, uppper
float, optional Lower/upper limits of the range.
At least one limit must be provided if bins don’t have a constant size. If both lower and upper limits are provided, the lower one will be prioritized.
- Returns:
- edges
ndarray, shape(n+1) Edges of the bins.
- edges
See also
Hist1d.from_centersCreate a
Hist1ddirectly from centers.
Examples
Get edges from equally spaced centers:
>>> ap.centers_to_edges([0.5, 1.5, 2.5, 3.5, 4.5]) [0. 1. 2. 3. 4. 5.]
Get edges from centers that are not equally spaced:
>>> ap.centers_to_edges([0.5, 1.5, 3.0, 4.5, 5.5], lower=0.0) [0. 1. 2. 4. 5. 6.] >>> ap.centers_to_edges([0.5, 1.5, 3.0, 4.5, 5.5], upper=6.0) [0. 1. 2. 4. 5. 6.]