3The
ROOT::RVec class has additional features in Python, which allow to adopt memory
4from Numpy arrays and vice versa. The purpose of these features is the copyless
5interfacing of Python and
C++ using their most common data containers, Numpy arrays
8### Conversion of RVecs to Numpy arrays
10RVecs of fundamental types (int, float, ...) have in Python the `__array_interface__`
11attribute attached. This information allows Numpy to adopt the memory of RVecs without
12copying the content. You can find further documentation regarding the Numpy array interface
14demonstrates the memory adoption mechanism using `numpy.asarray`.
17rvec = ROOT.RVec('double')((1, 2, 3))
18print(rvec) # { 1.0000000, 2.0000000, 3.0000000 }
20npy = numpy.asarray(rvec)
21print(npy) # [1. 2. 3.]
24print(npy) # [42. 2. 3.]
27### Conversion of Numpy arrays to RVecs
29Data owned by Numpy arrays with fundamental types (int, float, ...) can be adopted by RVecs. To
30create an RVec from a Numpy array, ROOT offers the facility ROOT.VecOps.AsRVec, which performs
31a similar operation to `numpy.asarray`, but vice versa. A code example demonstrating the feature and
32the adoption of the data owned by the Numpy array is shown below.
35npy = numpy.array([1.0, 2.0, 3.0])
36print(npy) # [1. 2. 3.]
38rvec = ROOT.VecOps.AsRVec(npy)
39print(rvec) # { 1.0000000, 2.0000000, 3.0000000 }
42print(rvec) # { 42.000000, 2.0000000, 3.0000000 }
A "std::vector"-like collection of values implementing handy operation to analyse them.
ROOT::VecOps::RVec< T > RVec
constexpr Double_t C()
Velocity of light in .