# Machine Learning on a Large Dataset using PyTorch: RDataFrame vs. uproot?

**URL:** <https://root-forum.cern.ch/t/machine-learning-on-a-large-dataset-using-pytorch-rdataframe-vs-uproot/53167>\
**Category:** ROOT\
**Tags:** rdataframe, python\
**Created:** [January 18, 2023, 7:13pm UTC](https://root-forum.cern.ch/t/machine-learning-on-a-large-dataset-using-pytorch-rdataframe-vs-uproot/53167 "2023-01-18T19:13:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam\_Kelson](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/sam_kelson/32/30278_2.png) [@Sam\_Kelson](https://root-forum.cern.ch/u/Sam_Kelson)\
**Post date:** [January 18, 2023, 7:13pm UTC](https://root-forum.cern.ch/t/machine-learning-on-a-large-dataset-using-pytorch-rdataframe-vs-uproot/53167/1 "2023-01-18T19:13:19Z")

</div>

Is there a general opinion on whether it is more efficient to load data via RDataFrames or uproot directly from ROOT files for machine learning analysis in PyTorch? I have seen discussion on this in multiple areas but most are fairly old and I am wondering if anything has changed in the past 2/3 years.

For my purposes specifically, I believe I will not be doing much fiddling around with the data itself and would like to avoid intermediate files assuming no loss in performance (are intermediate file methods much faster?). I just simply want to get the data from the ROOT files and into a PyTorch readable format in the most efficient manner possible.

Any links to external resources and comments are appreciated.

Thanks.

Older relevant post: [python - What the fastest, most memory-efficient way of opening a ROOT NTuple for machine learning? - Stack Overflow](https://stackoverflow.com/questions/58817554/what-the-fastest-most-memory-efficient-way-of-opening-a-root-ntuple-for-machine)

---

<div class="post-metadata">

**Author:** ![jalopezg](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jalopezg/32/25844_2.png) [@jalopezg](https://root-forum.cern.ch/u/jalopezg)\
**Post date:** [January 19, 2023, 12:01pm UTC](https://root-forum.cern.ch/t/machine-learning-on-a-large-dataset-using-pytorch-rdataframe-vs-uproot/53167/2 "2023-01-19T12:01:34Z")

</div>

Hi @Sam_Kelson,

Welcome to the ROOT forum! I’m inviting @moneta and @vpadulan to the topic, as I think they can shed some light on this.

Cheers,  
J.

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [January 19, 2023, 9:56pm UTC](https://root-forum.cern.ch/t/machine-learning-on-a-large-dataset-using-pytorch-rdataframe-vs-uproot/53167/3 "2023-01-19T21:56:36Z")

</div>

Hi Sam,

A simple way, if your dataset is not too large is to use, as pointed in the link above, `RDataFrame.AsNumpy`.  
If this is not convenient for your data, we are developing also a batch generator using RDataFrame which will provide efficiently batches of numpy arrays that can be used for ML tools like PyTorch or Tensorflow with minimal overhead. If you are interested we can provide you a prototype implementation for this

Best regards

Lorenzo

---

<div class="post-metadata">

**Author:** ![Sam\_Kelson](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/sam_kelson/32/30278_2.png) [@Sam\_Kelson](https://root-forum.cern.ch/u/Sam_Kelson)\
**Post date:** [February 1, 2023, 5:42am UTC](https://root-forum.cern.ch/t/machine-learning-on-a-large-dataset-using-pytorch-rdataframe-vs-uproot/53167/4 "2023-02-01T05:42:22Z")

</div>

Hi Lorenzo,

That batch generator sounds really interesting. A prototype implementation would be lovely if you could provide that for me.

Thanks!

Sam

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [February 15, 2023, 5:43am UTC](https://root-forum.cern.ch/t/machine-learning-on-a-large-dataset-using-pytorch-rdataframe-vs-uproot/53167/5 "2023-02-15T05:43:20Z")

</div>

Closed on February 15, 2023, 5:43am UTC

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

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [July 8, 2026, 3:51pm UTC](https://root-forum.cern.ch/t/machine-learning-on-a-large-dataset-using-pytorch-rdataframe-vs-uproot/53167/6 "2026-07-08T15:51:05Z")

</div>

Dear @Sam_Kelson ,

I am reviving this old conversation because now ROOT provides an interface for native data loading of ROOT data to popular ML tools, including PyTorch. This is available since ROOT 6.40 as `ROOT.Experimental.ML.RDataLoader`, you can find an example with PyTorch at [ROOT: tutorials/machine\_learning/ml\_dataloader\_PyTorch.py File Reference](https://root.cern/doc/v640/ml __dataloader__ PyTorch_8py.html) . For more details, I also encourage you to take a look at this recent public presentation [28th Conference on Computing in High Energy and Nuclear Physics (CHEP 2026) (25-29 May 2026): Optimizations and New Strategies for Native ROOT Data Loading for ML · Indico](https://indico.cern.ch/event/1471803/contributions/6968218/)

In case this is still relevant to you, we would welcome your feedback and we would also be available to help you in integrating the interface into your workflow.

Cheers,  
Vincenzo
