Dear experts,
is there a way to write a numpy array in a tree using RDataFrame.
I tried this example but it didnt work.
from ROOT import *
from ROOT import RDataFrame
# Read data from NumPy arrays
# The column names in the RDataFrame are taken from the dictionary keys
x, y = numpy.array([1, 2, 3]), numpy.array([4, 5, 6])
df = ROOT.RDF.MakeNumpyDataFrame({"x": x, "y": y})
# Use RDataFrame as usual, e.g. write out a ROOT file
df.Define("z", "x + y").Snapshot("tree", "file.root")
Hi @sara_sellam ,
you did not mention what the problem was with the script, but this works for me (I just had to fix the imports):
import ROOT
import numpy
# Read data from NumPy arrays
# The column names in the RDataFrame are taken from the dictionary keys
x, y = numpy.array([1, 2, 3]), numpy.array([4, 5, 6])
df = ROOT.RDF.MakeNumpyDataFrame({"x": x, "y": y})
# Use RDataFrame as usual, e.g. write out a ROOT file
df.Define("z", "x + y").Snapshot("tree", "file.root")