python - 具有类似于 Python/NumPy 的数组操作的 C++ 库

标签 python c++ arrays numpy

<分区>

请原谅我问了一个可能过于宽泛的问题。但是,我的任务非常具体:没有太多 Python 经验,我想将 Python 代码重写为 C++ (OpenCV),我想知道是否有针对某些 C++ 库的良好文档比较(我知道存在 OpenBLAS、Eigen、等),这将使我相对容易地重复原始代码中的所有数组操作,这对我使用 OpenCV 来说是一个相当大的挑战。也许有人真的写过关于语法比较的帖子?

Python代码:

image = im_orig.copy()
# Create input for multiples of net input/output changes.
im_bg_width = int(_np.ceil(
    float(image.shape[1]) * scale_factor / _STRIDE) * _STRIDE)
im_bg_height = int(_np.ceil(
    float(image.shape[0]) * scale_factor / _STRIDE) * _STRIDE)
pad_size = 64
im_bot_pixels = image[-1:, :, :]
im_bot = _np.tile(im_bot_pixels, (pad_size, 1, 1))
image = _np.vstack((image, im_bot))
im_right_pixels = image[:, -1:, :]
im_right = _np.tile(im_right_pixels, (1, pad_size, 1))
image = _np.hstack((image, im_right))
image = _scipy.misc.imresize(image, scale_factor, interp='bilinear')
image = image.astype('float32') - _MEAN

net_input = _np.zeros((im_bg_height, im_bg_width, 3), dtype='float32')
net_input[:min(net_input.shape[0], image.shape[0]),
          :min(net_input.shape[1], image.shape[1]), :] =\
    image[:min(net_input.shape[0], image.shape[0]),
          :min(net_input.shape[1], image.shape[1]), :]

编辑:我想不惜一切代价摆脱对 python 的依赖(尤其是对 python C++ API 的依赖),并使程序真正可读,这与 Cython 生成的程序不同。

最佳答案

我认为 Eigen 可能适合你。如果您还没有尝试过(根据您的问题我不知道),您应该看一看。除了速度非常快(据我所知,这是最快的),它还有一个非常自然的语法。如果只关注 C++,情况并不会好多少。

http://eigen.tuxfamily.org

关于python - 具有类似于 Python/NumPy 的数组操作的 C++ 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41861601/

相关文章:

python - 参数解析器错误 : too few arguments

python - Flask-login is_active 不会保持更改

python - 从 Django 查询集中获取 Django 值,其中列名是一个变量

c++ - 使用 cmake 构建 Qt 4 项目时出错

python 单行多用户输入

c++ - extern 常量,未命名的命名空间

c++ - 将带有前置和后置增量运算符的 C++ 转换为 Python 时出现问题

javascript - 覆盖 Array 构造函数不会影响 [],对吗?

java - 查找数组之间的相似值

javascript - JSON数组推送数组