Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
_rvec.pyzdoc
Go to the documentation of this file.
2
6and RVec with a std::vector interface.
7
8### Conversion of RVecs to Numpy arrays
9
13[here](https://numpy.org/doc/stable/reference/arrays.interface.html). The following code example
14demonstrates the memory adoption mechanism using `numpy.asarray`.
15
16\code{.py}
17rvec = ROOT.RVec('double')((1, 2, 3))
18print(rvec) # { 1.0000000, 2.0000000, 3.0000000 }
19
20npy = numpy.asarray(rvec)
21print(npy) # [1. 2. 3.]
22
23rvec[0] = 42
24print(npy) # [42. 2. 3.]
25\endcode
26
27### Conversion of Numpy arrays to RVecs
28
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.
33
34\code{.py}
35npy = numpy.array([1.0, 2.0, 3.0])
36print(npy) # [1. 2. 3.]
37
38rvec = ROOT.VecOps.AsRVec(npy)
39print(rvec) # { 1.0000000, 2.0000000, 3.0000000 }
40
41npy[0] = 42
42print(rvec) # { 42.000000, 2.0000000, 3.0000000 }
43\endcode
44
45\endpythondoc
#define a(i)
Definition RSha256.hxx:99
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
A "std::vector"-like collection of values implementing handy operation to analyse them.
Definition RVec.hxx:1530
ROOT::VecOps::RVec< T > RVec
Definition RVec.hxx:70
constexpr Double_t C()
Velocity of light in .
Definition TMath.h:114