Skip to content
This repository has been archived by the owner on Jan 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #20 from scikit-hep/bins_field
Browse files Browse the repository at this point in the history
adding new fields bins and allbins, to complement values and allvalues
  • Loading branch information
jpivarski authored Dec 13, 2018
2 parents 00d6057 + ec66503 commit 3a140f7
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions uproot_methods/classes/TH1.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,39 @@ def underflows(self):
def overflows(self):
return self[-1]

@property
def edges(self):
axis = self._fXaxis
if len(getattr(axis, "_fXbins", [])) > 0:
return numpy.array(axis._fXbins)
else:
return numpy.linspace(axis._fXmin, axis._fXmax, axis._fNbins + 1)

@property
def alledges(self):
axis = self._fXaxis
v = numpy.empty(axis._fNbins + 3)
v[0] = -numpy.inf
v[-1] = numpy.inf
v[1:-1] = self.edges
return v

@property
def bins(self):
edges = self.edges
out = numpy.empty((len(edges) - 1, 2))
out[:, 0] = edges[:-1]
out[:, 1] = edges[1:]
return out

@property
def allbins(self):
edges = self.alledges
out = numpy.empty((len(edges) - 1, 2))
out[:, 0] = edges[:-1]
out[:, 1] = edges[1:]
return out

@property
def values(self):
return numpy.array(self[1:-1])
Expand Down

0 comments on commit 3a140f7

Please sign in to comment.