convert python numpy log array expression to cpp xtensor

84 Views Asked by At

I'm trying to convert NumPy/python code to CPP/xtensor. I have difficulty converting the following statement.

data = pd.read_csv(input_file,sep=',')
v = data.values
x = v[1:]/v[:-1]
LX1 = np.log(x[t-(2*w) + 1:t - w + 1,:]) <=== how do I write this in cpp

How would I write this in xtensor?

1

There are 1 best solutions below

0
On

Slicing in xtensor can be done with views.

In python:

x[t-(2*w) + 1:t - w + 1,:]

In c++, with xtensor:

xt::view(x, xt::range(t - (2*w) + 1, t - w + 1), xt::all());

Logs in xtensor can be performed with xt::log()

You can also check conversions from numpy to xtensor in the From numpy to xtensor section.