1 Introduction

In this example, we will run Python inside R. You need to install the package reticulate and load the corresponding library.

import numpy as np
zp = np.array([1,2,3])
print(zp)
## [1 2 3]

We can port the Python array zp, into R as follows.

zr <- as.vector(py$zp)
zr
## [1] 1 2 3
xr= c(2,4,6)
xr
## [1] 2 4 6

We can also port things back into Python

wp = r.xr
wp = np.array(wp)
print(wp)
## [2. 4. 6.]
print(wp + zp)
## [3. 6. 9.]

2 Endnotes