Converting 2D histogram to numpy


After rebining my 2D histograms to get rid of some bin entries I try to convert them in numpy array, but I am surprised to see some negative numbers inside the numpy array while the histograms do not contains negative bin entries after rebining them. Could someone tell me please what is the issue?
Here the reduced code:

import matplotlib
import numpy as np
import ROOT
from ROOT import TCanvas, TPad, TFile, TPaveLabel, TPaveText
import root_numpy

from datetime import datetime  # # Used to compute the execution time

import matplotlib.pyplot as plt

myfile = TFile('../data/pseudoData_bkg_2D_all_channel_3-2GeVBin_mZd45_mH100GeV.root')
hdata2D = myfile.Get('pseudo_data_all')
hbkg2D = myfile.Get('bkg_all')

hdata2D_numpy, bins = root_numpy.hist2array(hdata2D, return_edges=True)
hbkg2D_numpy, bins = root_numpy.hist2array(hbkg2D, return_edges=True)

#printing the numpy 2D-Array
print("\nThe Numpy 2D-Array is:")
for i in hbkg2D_numpy:
    for j in i:
        print(j, end=" ")

I also attached the root files.
pseudoData_bkg_2D_all_channel_3-2GeVBin_mZd45_mH100GeV_reBin.root (6.6 KB)

Maybe @etejedor can help


I see that you are using root_numpy, this package is not provided by ROOT and therefore we can’t provide you support for it in this forum. I suggest that you contact the developers or any support channel of root_numpy.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.