从C++读取NPY文件

2024-10-01 15:41:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图直接在C++中读取NPY文件(NUMPYS MMAP格式),但遇到了一些困难。在

这个文件是用numpy编写的,可以很容易地用numpy读回(因此它没有损坏或其他任何东西)。在

我的第一次尝试是直接使用cnpy包(https://github.com/rogersce/cnpy),但是这会引发有关文件头大小的断言错误。在

有没有人在NUMPY中创建NPY文件并在C++中读取它的例子?在

干杯, 杰克


Tags: 文件httpsnumpygithubcom格式错误断言
1条回答
网友
1楼 · 发布于 2024-10-01 15:41:28
<>我将检查您的测试文件的前10个字节,以描述在{{CD1>}和C++代码

format.py文件文档头中的部分引用

Format Version 1.0
         

The first 6 bytes are a magic string: exactly ``\\x93NUMPY``.

The next 1 byte is an unsigned byte: the major version number of the file
format, e.g. ``\\x01``.

The next 1 byte is an unsigned byte: the minor version number of the file
format, e.g. ``\\x00``. Note: the version of the file format is not tied
to the version of the numpy package.

The next 2 bytes form a little-endian unsigned short int: the length of
the header data HEADER_LEN.

我还没有用另一种语言编写这个代码,但确实仔细研究了头文件,以便在同一个文件中保存多个数组。在

loading arrays saved using numpy.save in append mode

相关问题 更多 >

    热门问题