TGraph can not taking numpy arrays as arguments

Hello experts,

Sorry that if this problem has already been discussed extensively, but I am still getting errors when trying to pass numpy arrays as arguments to TGraph. The following is what I have been trying to do:

Am I missing something?

I am using version ‘6.22/06’ with Python 3.7 (Jupyter notebook)

graph = TGraph(3,np,array(a),np, array(b))

does not correspond to any of the TGraph valid constructors:

TGraph ()
Graph default constructor. More…
TGraph (const char *filename, const char *format="%lg %lg", Option_t *option="")
Graph constructor reading input from filename. More…
TGraph (const TF1 *f, Option_t *option="")
Graph constructor importing its parameters from the TF1 object passed as argument. More…
TGraph (const TGraph &gr)
Copy constructor for this graph. More…
TGraph (const TH1 *h)
Graph constructor importing its parameters from the TH1 object passed as argument. More…
TGraph (const TVectorD &vx, const TVectorD &vy)
Graph constructor with two vectors of doubles in input A graph is build with the X coordinates taken from vx and Y coord from vy The number of points in the graph is the minimum of number of points in vx and vy. More…
TGraph (const TVectorF &vx, const TVectorF &vy)
Graph constructor with two vectors of floats in input A graph is build with the X coordinates taken from vx and Y coord from vy The number of points in the graph is the minimum of number of points in vx and vy. More…
TGraph (Int_t n)
Constructor with only the number of points set the arrays x and y will be set later. More…
TGraph (Int_t n, const Double_t *x, const Double_t *y)
Graph normal constructor with doubles. More…
TGraph (Int_t n, const Float_t *x, const Float_t *y)
Graph normal constructor with floats. More…
TGraph (Int_t n, const Int_t *x, const Int_t *y)
Graph normal constructor with ints. More…

@couet Assuming there was “import numpy as np” then “np.array(a)” is not “np,array(a)”. :wink:

Maybe you need to explicitly provide the type (dtype when passing to TGraph), or use astype first, to make sure ROOT knows what they are?

oops sorry… it did not read well … I saw a coma instead of a dot… it’s time to change my glasses :wink:

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