简体   繁体   English

xtensor:如何将向量写入数组

[英]xtensor : How to write an vector to an array

What is the equivalent in xtensor or the most optimized way to write a vector to an array. xtensor中的等价物或将向量写入数组的最优化方式是什么。

Thanks谢谢

import numpy as np

array = np.zeros((4, 4))

array[0] = np.array([1, 2, 3, 4]) # this

The easiest way is最简单的方法是

#include <xtensor/xtensor.hpp>
#include <xtensor/xarray.hpp>
#include <xtensor/xview.hpp>
#include <xtensor/xio.hpp>

int main()
{
    xt::xtensor<double, 2> array = xt::xtensor<double>({4, 4});
    xt::xtensor<double, 1> row = {1, 2, 3, 4};
    xt::view(array, 0) = row;

    return 0;
}

You can use xt::xarray for flexibility, but it is less efficient.您可以使用xt::xarray来获得灵活性,但效率较低。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM