Qt使用Numcpp(c++版的Numpy)
本文最后更新于:2023年3月20日 晚上
Qt使用Boost_Numcpp库
(1) 下载boost_1.75.0库文件
(2) 下载Numcpp: C++ implementation of the Python Numpy library
(3) 非中文路径下新建文件夹D:_Numcpp,将boost_1.75.0文件夹中的boost文件夹复制进刚刚新建的文件夹中,并将Numcpp中的includes文件夹中的NumCpp和NumCpp.hpp复制进刚刚新建的文件夹中(无需添加环境变量)
(4) 在Qt控制台项目的配置文件.pro中,修改CONFIG += c++14,并添加库文件路径,配置文件.pro内容如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29QT -= gui
CONFIG += c++14 console
CONFIG -= app_bundle
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp
TRANSLATIONS += \
Boost_Numcpp_Test_zh_CN.ts
# Boost库文件路径添加
INCLUDEPATH += D:\Boost_Numcpp
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
(5) 测试代码
1
2
3
4
5
6
7
8
9
10
11
12
13boost::timer tmr;
qDebug() << tmr.elapsed() << "S" << endl;
qDebug() << BOOST_VERSION << endl;
qDebug() << BOOST_LIB_VERSION << endl;
qDebug() << BOOST_PLATFORM << endl;
qDebug() << BOOST_COMPILER << endl;
qDebug() << BOOST_STDLIB << endl;
nc::NdArray<float> m1 = {{1, 2}, {3, 4}};
nc::NdArray<float> m2 = {{1, 2}, {3, 4}};
nc::NdArray<float> m3 = m1 * m2;
std::cout << m3 << std::endl;
return a.exec();
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!