Are you sure you want to delete this task? Once this task is deleted, it cannot be recovered.
Darren d7c1294d9e | 3 years ago | |
---|---|---|
.. | ||
CMakeLists.txt | 3 years ago | |
LICENSE | 3 years ago | |
README.md | 3 years ago | |
cnpy.cpp | 3 years ago | |
cnpy.h | 3 years ago | |
example1.cpp | 3 years ago | |
mat2npz | 3 years ago | |
npy2mat | 3 years ago | |
npz2mat | 3 years ago |
NumPy offers the save
method for easy saving of arrays into .npy and savez
for zipping multiple .npy arrays together into a .npz file.
cnpy
lets you read and write to these formats in C++.
The motivation comes from scientific programming where large amounts of data are generated in C++ and analyzed in Python.
Writing to .npy has the advantage of using low-level C++ I/O (fread and fwrite) for speed and binary format for size.
The .npy file header takes care of specifying the size, shape, and data type of the array, so specifying the format of the data is unnecessary.
Loading data written in numpy formats into C++ is equally simple, but requires you to type-cast the loaded data to the type of your choice.
Default installation directory is /usr/local.
To specify a different directory, add -DCMAKE_INSTALL_PREFIX=/path/to/install/dir
to the cmake invocation in step 4.
To use, #include"cnpy.h"
in your source code. Compile the source code mycode.cpp as
g++ -o mycode mycode.cpp -L/path/to/install/dir -lcnpy -lz --std=c++11
There are two functions for writing data: npy_save
and npz_save
.
There are 3 functions for reading:
npy_load
will load a .npy file.npz_load(fname)
will load a .npz and return a dictionary of NpyArray structues.npz_load(fname,varname)
will load and return the NpyArray for data varname from the specified .npz file.The data structure for loaded data is below.
Data is accessed via the data<T>()
-method, which returns a pointer of the specified type (which must match the underlying datatype of the data).
The array shape and word size are read from the npy header.
struct NpyArray {
std::vector<size_t> shape;
size_t word_size;
template<typename T> T* data();
};
See example1.cpp for examples of how to use the library. example1 will also be build during cmake installation.
该算法把样本聚类和特征学习融合到一个端到端的网络框架中,提升模型的跨域能力。该模型在Market训练,DukeMTMC上测试能达到82.0%的准确率,在DukeMTMC上训练,Market上测试能达到92.2%的准确率。
Text Python C++ Protocol Buffer Markdown other
Dear OpenI User
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.
For more agreement content, please refer to the《Openl Qizhi Community AI Collaboration Platform Usage Agreement》