'How to create custom tensor value with shape (b,n,m)?

How to create custom tensor value with shape (b,n,m) I see the cppflow::fill method but it allows inserting 1 value which fills the whole same value in the shape I see https://github.com/serizba/cppflow/issues/114 but have not found how to fill the value from the custom value or vector for example

I've already created a 2d vector using

    vector<vector<float>> tensordata;
  
    for(int i=0; i<cloud->points.size(); i++)
    {
        vector<float> temp;
        for(int j=0; j<3; j++)
        {
            if(j==0)
            {
                temp.push_back(cloud->points[i].x);
            }
            if(j==1)
            {
                temp.push_back(cloud->points[i].y);
            }
            if(j==2)
            {
                temp.push_back(cloud->points[i].z);
            }            
        }
        tensordata.push_back(temp);
    }

but still, there's an error to convert it into a tensor.



Solution 1:[1]

Create a vector of floats (a 1 dimensional vector, not a vector of vectors). vector<float> tensor_data;

Fill the vector using tensor_data.push_back() as if it was 1d data.

Initialize a cppflow tensor with the right dimensions using the vector.

cppflow::tensor tnsr = cppflow::tensor(tensor_data, { b, n, m});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 YScharf