Skip to main content

An interface between ROOT and NumPy

Project description

https://travis-ci.org/rootpy/root_numpy.png https://pypip.in/v/root_numpy/badge.png https://pypip.in/d/root_numpy/badge.png

root_numpy is a Python extension for converting ROOT TTrees into NumPy recarrays or structured arrays as well as converting NumPy arrays back into ROOT TTrees. With the core internals written in C++, root_numpy can efficiently handle large amounts of data (limited only by the available memory). Now that your ROOT data is in NumPy form, you can make use of the many powerful scientific Python packages or perform quick exploratory data analysis in interactive environments like IPython (especially IPython’s popular notebook feature).

root_numpy currently supports basic types such as bool, int, float, double, etc. and arrays of basic types (both variable and fixed-length). Vectors of basic types are also supported.

See the root2hdf5 script in the rootpy package that uses root_numpy and PyTables to convert all TTrees in a ROOT file into the HDF5 format.

import ROOT
from root_numpy import root2array, root2rec, tree2rec

# convert into a numpy structured array
# treename is always optional if there is only one tree in the file
arr = root2array('a.root', 'treename')

# convert into a numpy record array
rec = root2rec('a.root', 'treename')

# or directly convert a tree
rfile = ROOT.TFile('a.root')
tree = rfile.Get('treename')
rec = tree2rec(tree)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

root_numpy-3.0.1.tar.gz (269.7 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page