I am new to the xtensor. I am wondering how one would use the output from xt::where. In python, for example assuming imap is an nd array, np.where(imap>=4) returns two arrays with indices and can be assigned directly using the = operator. Please let me know how to use it in the xtensor C++ context. Any small example would be a great help.
Thanks.
returns xt::xarray of input type.
xt::xarray<int> res = xt::where(b, a1, a2);
b
is a true then elements of array a1
are returned, if b
is false elements of a2
are returned.
The below example is copied from documentation (search for xt::where
)
http://xtensor.readthedocs.io/en/latest/operator.html
b's first element is false
- so get it from a2
-- 11
b's second element is true
- so get it from a1
-- 2
b's third element is true
- so get it from a1
-- 3
b's fourth element is false
- so get it from a2
-- 14
xt::xarray<bool> b = { false, true, true, false };
xt::xarray<int> a1 = { 1, 2, 3, 4 };
xt::xarray<int> a2 = { 11, 12, 13, 14 };
xt::xarray<int> res = xt::where(b, a1, a2);
// => res = { 11, 2, 3, 14 }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With