NumCpp是python中numpy库的c++版本。
下载NumCpp
git clone https://github.com/dpilger26/NumCpp.git
下载boost,下述安装链接为范例,需要随boost版本升级进行修改…
wget https://boostorg.jfrog.io/artifactory/main/release/1.81.0/source/boost_1_81_0.tar.gz
sudo apt update
sudo apt install libboost-all-dev
dpkg -S /usr/include/boost/version.hpp #检查boost版本
tar -zxvf boost_1_81_0.tar.gz
cd boost_1_81_0
./bootstrap.sh --with-libraries=all --with-toolset=gcc
sudo ./b2 install --prefix=/usr
cd NumCpp
mkdir build
cd build
cmake ..
sudo cmake --build . --target install
cd ..
创建cpp文件test.cpp,输入以下命令:
#include <iostream>
#include "NumCpp.hpp"
int main() {
nc::NdArray<float> a = {{1, 2}, {3, 4}};
nc::NdArray<float> b = {{1, 2}, {3, 4}};
nc::NdArray<float> c = a * b;
std::cout << c[0] << std::endl;
return 0;
}
编译运行test.cpp文件(注意,这里的编译器必须是c++14以上)
g++ -o test test.cpp --std=c++14
./test
输出:
1
通过测试。
Reference:
https://blog.csdn.net/qq_44718846/article/details/119731424
https://blog.csdn.net/Tosonw/article/details/91860627