diff --git a/README.md b/README.md index 1d344293e..9934b94bd 100644 --- a/README.md +++ b/README.md @@ -125,8 +125,10 @@ histograms can be plotted via any compatible library, such as [mplhep][]. * `*=`: Multiply by a scaler (not all storages) (`hist * scalar` and `scalar * hist` supported too) * `/=`: Divide by a scaler (not all storages) (`hist / scalar` supported too) * `.kind`: Either `bh.Kind.COUNT` or `bh.Kind.MEAN`, depending on storage + * `._storage_type`: Fetch histogram storage type class * `.sum(flow=False)`: The total count of all bins * `.project(ax1, ax2, ...)`: Project down to listed axis (numbers). Can also reorder axes. + * `.compare(second_hist)`: Compare the histogram with another histogram * `.to_numpy(flow=False, view=False)`: Convert to a NumPy style tuple (with or without under/overflow bins) * `.view(flow=False)`: Get a view on the bin contents (with or without under/overflow bins) * `.values(flow=False)`: Get a view on the values (counts or means, depending on storage) diff --git a/src/boost_histogram/_internal/hist.py b/src/boost_histogram/_internal/hist.py index 80d27c4bf..b397f5217 100644 --- a/src/boost_histogram/_internal/hist.py +++ b/src/boost_histogram/_internal/hist.py @@ -337,6 +337,17 @@ def ndim(self) -> int: """ return self._hist.rank() + def compare(self, hist2: "Histogram") -> str: + if not np.allclose(self.view().shape, hist2.view().shape): + return f"The histogram dimensions [{self.view().shape} and {hist2.view().shape}] are not equal." + if not np.allclose(self.view(), hist2.view()): + return f"The histogram contents :\n {self.view()} \nand\n {hist2.view()} \nare not equal." + if self._storage_type != hist2._storage_type: + return f"The storage types ({str(self._storage_type).rsplit('.', maxsplit=1)[-1][:-2]} and {str(hist2._storage_type).rsplit('.', maxsplit=1)[-1][:-2]}) are not equal." + if list(self.axes) != list(hist2.axes): + return f"The axes :\n {list(self.axes)} \nand\n {list(hist2.axes)} \nare not equal." + return "" + def view( self, flow: bool = False ) -> Union["np.typing.NDArray[Any]", WeightedSumView, WeightedMeanView, MeanView]: