如何导入pywt库,它是dev c++中的python库?

2024-09-29 23:17:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在试着运行这段代码,这段代码是我联系不到的人提取的, 该代码计算平方矩阵的dwt2和idwt2

#include <iostream>
#include <pywt>
#include <numpy>

using namespace std;

int main() {
int Matrix=numpy.array([[1.0,2.0,3.0,4.0,],[5.0,6.0,7.0,8.0,],[9.0,10.0,11.0,12.0,],[13.0,14.0,15.0,16.0,],])

cout << "-----------------------------------------------------------------";

cout << "Matrix : \n";

cout << Matrix[0];

int A,(B,C,D)=pywt.dwt2(Matrix,'haar', mode='symmetric')

cout << "-----------------------------------------------------------------";
cout << "A : \n";
cout << A[0];
cout << "-----------------------------------------------------------------";
cout << "B : \n";
cout << B[0];
cout << "-----------------------------------------------------------------";
cout << "C : \n";
cout << C[0];
cout << "-----------------------------------------------------------------";
cout << "D : \n";
cout << D[0];

int newMatrix=pywt.idwt2((A,(B,C,D)),'haar',mode='symmetric')

cout << "-----------------------------------------------------------------";
cout << "newMatrix : \n";
cout << newMatrix;

return 0;
}

Numpy库的链接:https://github.com/numpy/numpy pywt库的链接:https://github.com/PyWavelets/pywt

他说这些库既用于Python和C++,也只是把它们放在与C++代码相同的文件夹中,但我是C++的新手,我尝试了很多方法来工作,并在^ {CD1>}中包含库,但我仍然得到相同的错误,^ {CD2>},我不能导入库并使代码工作,请您帮助我。p>

非常感谢你


Tags: 代码httpsnumpyinclude链接modematrixint
1条回答
网友
1楼 · 发布于 2024-09-29 23:17:12

我看到您使用的是MinGW64,因此我认为您使用的是IDE代码块。要在代码块中添加库,请转到设置->;编译器->;全局编译器设置->;搜索目录->;并从下载的文件夹中添加include目录。然后,执行链接器设置,然后添加所需的库

你可以读一篇有用的文章here

顺便说一下,你可以用C++来做。我认为这更容易做到。这就是代码:

#include <iostream>

using namespace std;

int main()
{
    //this is the declared matrix
    float matrix[4][4]={{1.0,2.0,3.0,4.0},{5.0,6.0,7.0,8.0},{9.0,10.0,11.0,12.0},{13.0,14.0,15.0,16.0}};

    //this is the equivalent of the following line from your code
    //cout << "                          ";
    //I used a for loop to print 65 - characters
     for(int i=0;i<65;i++)cout<<'-';

    cout<<"\nMatrix:\n";

    //That's how basically we print a matrix, using 2 for loops
    //one for each row, and one for each column
    for(int i=0;i<4;i++)
    {
        for(int j=0;j<4;j++)cout<<matrix[i][j]<<' ';

        cout<<'\n';

        for(int i=0;i<65;i++)cout<<'-';

        cout<<'\n';
    }

}

这是一幅带有结果的图像: result

相关问题 更多 >

    热门问题