{
"cells": [
{
"cell_type": "markdown",
"id": "1c8492ed",
"metadata": {},
"source": [
"# tmva002_RDataFrameAsTensor\n",
"This tutorial shows how the content of an RDataFrame can be converted to an\n",
"RTensor object.\n",
"\n",
"\n",
"\n",
"\n",
"**Author:** Stefan Wunsch \n",
"This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, May 19, 2026 at 08:22 PM."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "80c6bf3e",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:22:30.570947Z",
"iopub.status.busy": "2026-05-19T20:22:30.570824Z",
"iopub.status.idle": "2026-05-19T20:22:30.891197Z",
"shell.execute_reply": "2026-05-19T20:22:30.890539Z"
}
},
"outputs": [],
"source": [
"using namespace TMVA::Experimental;"
]
},
{
"cell_type": "markdown",
"id": "af21f3d5",
"metadata": {},
"source": [
"Creation of an RDataFrame with five entries filled with ascending numbers"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "80156dcc",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:22:30.892929Z",
"iopub.status.busy": "2026-05-19T20:22:30.892813Z",
"iopub.status.idle": "2026-05-19T20:22:31.097059Z",
"shell.execute_reply": "2026-05-19T20:22:31.096389Z"
}
},
"outputs": [],
"source": [
"ROOT::RDataFrame df(5);\n",
"auto df2 = df.Define(\"x\", \"1.f*rdfentry_\").Define(\"y\", \"-1.f*rdfentry_\");"
]
},
{
"cell_type": "markdown",
"id": "9ccb23b1",
"metadata": {},
"source": [
"Convert content of columns to an RTensor object"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "210144bc",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:22:31.098716Z",
"iopub.status.busy": "2026-05-19T20:22:31.098580Z",
"iopub.status.idle": "2026-05-19T20:22:32.469614Z",
"shell.execute_reply": "2026-05-19T20:22:32.469034Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"RTensor from an RDataFrame:\n",
"{ { 0, -0 } { 1, -1 } { 2, -2 } { 3, -3 } { 4, -4 } }\n",
"\n"
]
}
],
"source": [
"auto x = AsTensor(df2);\n",
"\n",
"std::cout << \"RTensor from an RDataFrame:\\n\" << x << \"\\n\\n\";"
]
},
{
"cell_type": "markdown",
"id": "5a7d706a",
"metadata": {},
"source": [
"The utility also supports reading only a part of the RDataFrame and different\n",
"memory layouts."
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "c5e7487d",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:22:32.471475Z",
"iopub.status.busy": "2026-05-19T20:22:32.471357Z",
"iopub.status.idle": "2026-05-19T20:22:32.716766Z",
"shell.execute_reply": "2026-05-19T20:22:32.716251Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"RTensor from a single column of the RDataFrame:\n",
"{ { 0 } { 1 } { 2 } { 3 } { 4 } }\n",
"\n"
]
}
],
"source": [
"auto x2 = AsTensor(df2, {\"x\"}, MemoryLayout::ColumnMajor);\n",
"\n",
"std::cout << \"RTensor from a single column of the RDataFrame:\\n\" << x2 << \"\\n\\n\";"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "ROOT C++",
"language": "c++",
"name": "root"
},
"language_info": {
"codemirror_mode": "text/x-c++src",
"file_extension": ".C",
"mimetype": " text/x-c++src",
"name": "c++"
}
},
"nbformat": 4,
"nbformat_minor": 5
}