How to modify a 2d tensor to 3d in libtorch?
I have a 2d array vector&lt;vector&gt;, I have coverted it to tensor, but how to modify the dimension of the tensor, I want to modify the dimension from 2d to 3d?
std::vector&lt;std::vector&lt;float&gt;&gt; voice(434, std::vector&lt;float&gt;(80))
ifstream fp(&quot;data.txt&quot;);
if (! fp) {
    cout &lt;&lt; &quot;Error, file couldn't be opened&quot; &lt;&lt; endl; 
    return 1; 
}    
for(int i=0;i&lt;80;i++)
{
    for(int j=0;j&lt;434;j++)
    {
        if ( ! fp ) 
        {
            std::cout &lt;&lt; &quot;read error&quot; &lt;&lt; std::endl;
            break;
        }
        fp &gt;&gt; voice[i][j]
    }
}

auto options = torch::TensorOptions().dtype(at::kDouble);
auto tensor = torch::zeros({80,434}, options);
for (int i = 0; i &lt; 80; i++)
    tensor.slice(0, i,i+1) = torch::from_blob(vect[i].data(), {434}, options);

Now the tensor is 80 * 434, how can I add one dimension in this tensor to 3d, I want 1 * 80 * 434

auto tensor = torch::zeros({80,434}, options);

followed by this line
auto tensor = tensor.view({1, 80, 434});

I would recommend to create another variable instead of tensor in the second line, like:
auto transformed_tensor = tensor.view({1, 80, 434});

