gpt4 book ai didi

c++ - 在 Armadillo 中对立方体切片进行操作

转载 作者:行者123 更新时间:2023-11-30 05:10:56 25 4
gpt4 key购买 nike

我正在努力适应 C++ 的 Armadillo 线性代数库,但我无法弄清楚如何对立方体的切片(矩阵)进行操作。每当我尝试对切片进行操作时,程序都会编译但不提供任何输出,甚至不提供切片操作之前语句的输出。这是代码:

#include <armadillo>
#include <iostream>
using namespace arma;
using namespace std;

int main()
{

Cube<double> A(3 , 5 ,1, fill::randu);

Cube<double>B(5,3,1,fill::randu);
Mat<double>x =A.slice(0);
Mat<double>y = B.slice(0);
cout << x << "\n" << y << endl;
cout << x*y << endl; //code works fine if this line is removed
}

问题是如果最后一行被删除,代码可以正常工作。为什么会这样?有没有更好的方法来操作立方体内的矩阵?

最佳答案

使用 this 的已接受答案中给出的说明问题,使用 Visual Studio 在 Windows 上安装 Armadillo 。

如果您要求链接器使用 blas_win64_MT.liblapack_win64_MT.lib 库,请确保添加相应的 .dll'与您的 .exe 文件位于同一目录中。然后使用此代码,我得到了所需的输出。

#include <armadillo>
#include <iostream>

using namespace std;
using namespace arma;

int main()
{
Cube<double> A(3, 5, 1, fill::randu);
Cube<double> B(5, 3, 1, fill::randu);

Mat<double> x = A.slice(0);
Mat<double> y = B.slice(0);

std::cout << "x:\n" << x << "\ny:\n" << y << std::endl;
std::cout << "x*y:\n" << x*y << std::endl;
}

命令窗口输出:

Armadillo Cube Demo

希望对您有所帮助!

关于c++ - 在 Armadillo 中对立方体切片进行操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45385449/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com