I’ve started using PyROOT (because python rocks!). I was wondering if anyone knew how to do the following in python:

#include <stdio.h>
#include <TMath.h>

int main()
int x[12] = {8,2,4,2,4,2,4,4,1,5,6,3};
double mean = TMath::Mean(12, x);
double median = TMath::Median(12, x);
printf("%lf %lf\n", mean, median);

here’s my best attempt but it the numbers for mean and median are wrong:

from ROOT import TMath
from array import array

x=array(‘i’, [8,2,4,2,4,2,4,4,1,5,6,3])

mean=TMath.Mean(12, x)
median=TMath.Median(12, x)

print mean, median


The problem I’m having is with TMath, I think.
I’m using ROOT 4.02/00 pro



what happens, in both cases, is that the overload attempts a match-up with Short_t*.
Since short is not a special case, the array gets converted from an int* to a void*
and then matches the overload. Arrays are a little tricky to handle and I have therefore
special cases for char, int, long, float, and double written out.

The problem is that I have been mislead by the documentation of array. In python 2.2,
the table (see: ) does not contain short.
However, a closer look shows that there is an int of size 2, so I should have added a
special handle for short. (I can’t add a check that prevents passing any buffer-like
object with a type code through the void* converter, because it is valid to pass e.g. a
char array through a void* as a buffer.)

Note that even for p2.4 there’s still a problem: long long is missing as a typecode, but
I think I can match up a special case for that one too.

In any case, sorry for this and thanks for reporting, a fix should appear soon.

Best regards,


fix is in CVS. Thanks again.

Best regards,

Nice one! On with upgradage!