xtensor icon indicating copy to clipboard operation
xtensor copied to clipboard

Reshape Array

Open CHIRAGGANDHI opened this issue 2 years ago • 1 comments

Currently I am using diff function to get difference but like python diff function (np.diff(WWdx, axis=1, prepend=0, append=0), it doesn't have prepand and append parameter.

I have array defined as below,

xt::xarray a = { {0, 1, 2}, {4, 5, 6}, {8, 9, 10} };

Now I would like to add an extra column with all the value 0. So it would look like below,

xt::xarray a = { {0, 1, 2, 0}, {4, 5, 6, 0}, {8, 9, 10, 0} };

CHIRAGGANDHI avatar Jul 24 '21 03:07 CHIRAGGANDHI

One thing you can do is

xt::xarray<double> b = xt::empty<double>({a.shape(0), a.shape(1) + 1});
xt::view(b, xt::all(), xt::range(3)) = a;
a = b;

but there are probably more efficient solutions

tdegeus avatar Aug 03 '21 12:08 tdegeus