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

C++ library with array operations similar to Python/NumPy

本文关键字:数组 操作 NumPy 类似于 Python C++      更新时间:2023-10-16

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

蟒蛇代码:

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