如何在libtorch中将2d张量修改为3d?
我有一个2d数组向量
std::vector<std::vector<float>> voice(434, std::vector<float>(80))
ifstream fp("data.txt");
if (! fp) {
cout << "Error, file couldn't be opened" << endl;
return 1;
}
for(int i=0;i<80;i++)
{
for(int j=0;j<434;j++)
{
if ( ! fp )
{
std::cout << "read error" << std::endl;
break;
}
fp >> voice[i][j]
}
}
auto options = torch::TensorOptions().dtype(at::kDouble);
auto tensor = torch::zeros({80,434}, options);
for (int i = 0; i < 80; i++)
tensor.slice(0, i,i+1) = torch::from_blob(vect[i].data(), {434}, options);
现在张量
是80 * 434,我怎样才能将这个张量
中的一维添加到3d,我想要1 * 80 * 434
I have a 2d array vector<vector>, 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<std::vector<float>> voice(434, std::vector<float>(80))
ifstream fp("data.txt");
if (! fp) {
cout << "Error, file couldn't be opened" << endl;
return 1;
}
for(int i=0;i<80;i++)
{
for(int j=0;j<434;j++)
{
if ( ! fp )
{
std::cout << "read error" << std::endl;
break;
}
fp >> voice[i][j]
}
}
auto options = torch::TensorOptions().dtype(at::kDouble);
auto tensor = torch::zeros({80,434}, options);
for (int i = 0; i < 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这一行之后,
我建议在第二行中创建另一个变量而不是张量,例如:
followed by this line
I would recommend to create another variable instead of
tensor
in the second line, like: