Tmva 0 0 2_ R Data Frame As Tensor

This tutorial shows how the content of an RDataFrame can be converted to an RTensor object.

Author: Stefan Wunsch
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Saturday, September 18, 2021 at 09:30 AM.

In [1]:
using namespace TMVA::Experimental;

Creation of an rdataframe with five entries filled with ascending numbers

In [2]:
ROOT::RDataFrame df(5);
auto df2 = df.Define("x", "1.f*rdfentry_").Define("y", "-1.f*rdfentry_");

Convert content of columns to an rtensor object

In [3]:
auto x = AsTensor<float>(df2);

std::cout << "RTensor from an RDataFrame:\n" << x << "\n\n";
RTensor from an RDataFrame:
{ { 0, -0 } { 1, -1 } { 2, -2 } { 3, -3 } { 4, -4 } }

The utility also supports reading only a part of the rdataframe and different memory layouts.

In [4]:
auto x2 = AsTensor<float>(df2, {"x"}, MemoryLayout::ColumnMajor);

std::cout << "RTensor from a single column of the RDataFrame:\n" << x2 << "\n\n";
RTensor from a single column of the RDataFrame:
{ { 0 } { 1 } { 2 } { 3 } { 4 } }