Rebbing a histogram in pyroot

Dear Experts

Would you please let me know how I can rebin a histogram i.e. TH1F in python.
Here is what I have done, but I see some irrelevant errors:

from ctypes import *
inclusiveBinning = py_object([0,50,100,300,500,1000])
inclusiveBinningP= pointer(inclusiveBinning)

theFile = TFile(“Data.root”)
Histo = theFile.Get(“Mass_inclusive”)

hist_rebinned = Histo.Rebin(5,“rebinned”,inclusiveBinningP)

and here is the error:
Error in TAxis::TAxis::Set: bins must be in increasing order

Cheers
Abdollah

Abdollah,

(This is the wrong place to post, a mod may want to move it to the PyROOT forum.)

In this:from ctypes import * inclusiveBinning = py_object([0,50,100,300,500,1000]) inclusiveBinningP= pointer(inclusiveBinning)
you are creating a void* pointer to a PyObject* of list type (containing PyObject*'s of int type). That is allowed to pass through a double* under ‘user knows best’ (nothing else can be said about a void* after all).

However, what you want is a pointer to an array of doubles. So, create an array of doubles:import array inclusiveBinning = array.array('d', [0,50,100,300,500,1000])
HTH,
Wim

Many Thanks.
It works now!

Cheers
Abdollah