2016-08-23 8 views
0

C++でnpyファイル(numpys mmap形式)を直接読み込もうとしていますが、いくつかの問題がありました。C++からのnpyファイルの読み込み

ファイルはnumpyを使用して書かれており、numpyを使用して簡単に読み戻すことができます(破損していないなど)。

私の最初の試みでは、cnpyパッケージ(https://github.com/rogersce/cnpy)を直接使用していましたが、これはファイルヘッダーのサイズに関するアサーションエラーをスローします。

npyファイルをnumpyで作成してC++で読む例はありますか?

乾杯、 ジャック

+0

私は(A)[これらの1](http://docs.scipy.org/doc/scipy/reference/ioのようないくつかの広くサポートマトリックスファイル形式を使用するのが賢明だろうと思います。 html)または(B)いくつかのカスタマイズされたコードを書いてください。 – sascha

+0

.npyを書き込むコードはPythonであり、ヘッダーサイズを簡単に決定する必要があります。 'lib/format.py'のようなものを探します。 numpyがない場合は、githubリポジトリを参照してください。 – hpaulj

答えて

2

私はnp.lib.formatに説明と照らし合わせてテストファイルの最初の10のバイトをチェックして、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. 

私は別の言語でこれをコード化していませんが、同じファイルにいくつかの配列を保存したいというSOのヘッダを少し見ました。

loading arrays saved using numpy.save in append mode

関連する問題