基于 C++ 的 NumPy N 维补丁提取。
项目描述
npy-cpp-补丁
.npy从文件中读取 N 维补丁。该模块是使用C++并具有Python3绑定构建的。
数据规格
- 数组必须以
C-contiguous格式保存,即NOTFortran-contiguous。 - 第一个维度以非连续方式使用索引。例如,这可用于提取自然图像中的特定通道。
- 下一个维度由补丁形状
C++向量或Python元组指定。要提取比数据低维的补丁,请将相应的维度设置为1。
Python 用法
安装
pip install npy-patcher
用法
from npy_patcher import PatcherDouble, PatcherFloat, PatcherInt, PatcherLong
# In this example lets say our data has shape (10, 90, 90), and is therefore 3D.
data_fpath = '/my/numpy/file.npy'
patcher = PatcherFloat() # Use PatcherFloat for np.float32 datatype
nc_index = [0, 1, 3, 5, 7] # Non-contiguous index
patch_shape = (30, 30) # Contiguous patch shape.
patch_num = 2
# The patch number indexes the patches (starting from 0). So in our example the index 2 would be equivalent to data[nc_index, 0:30, 60:90]. The variable indexes the patches in C-contiguous manner, i.e. the last dimension has the smallest stride.
patch = patcher.get_patch(data_fpath, nc_index, patch_shape, patch_num)
patch = patch.reshape((5, 30, 30)) # PatcherFloat returns a list, therefore we need to reshape.
C++ 用法
下面是一个用 写的例子C++,相当于Python上面的用法。
// test.cpp
#include "src/patcher.hpp"
#include <vector>
#include <string>
int main() {
std::string fpath = "data.npy";
std::vector<size_t> nc_index {0, 1, 3, 5, 7};
std::vector<size_t> patch_shape {30, 30};
size_t patch_num = 2;
Patcher<float> patcher;
// Here the patch object is a contiguous 1D vector
std::vector<float> patch = patcher.get_patch(fpath, nc_index, patch_shape, patch_num);
return 0;
}
然后,您可以构建包,例如使用g++:
$ cd npy-cpp-patches/
$ g++ -std=c++17 -I ./ -g test.cpp src/npy_header.cpp src/pyparse.cpp -o test
项目详情
关
npy_patcher -1.0.8-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | cf88ec9830f8330135fc7447660380acd3ee5f730e4d5ba9a57b52fd4c261407 |
|
| MD5 | cd421b21d64a5a17edb045cb787c7c6c |
|
| 布莱克2-256 | 975f4e6fe83b133706410a99ed650cd74b25aeb218a0c03a178547c41f0629e8 |
关
npy_patcher -1.0.8-pp39-pypy39_pp73-manylinux_2_17_i686.manylinux2014_i686.whl 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | f6ef5d481db508def3eea01b1fb8b9ef1299c30f29434d79df015aee72bcf19b |
|
| MD5 | 8e0be1de448b6dbd2dae6d2d0150c1dc |
|
| 布莱克2-256 | 3f13ea267fbc13b75c921738ee8e533862d98719b4ff6949b377580ad87cfb12 |
关
npy_patcher -1.0.8-pp39-pypy39_pp73-macosx_10_9_x86_64.whl 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | 1c6f3538ab498712785872bfd7608f2ce1ceb0d8e528941bd076e2d8a3314cef |
|
| MD5 | 7bfd2547b42955e292d0129d8e6653b1 |
|
| 布莱克2-256 | b0c2812d387814b84d91aeaeb5927c1a591d65b7ffbc7aa94ccd97bd8208cce5 |
关