将numpy数组保存到二进制fi

2024-04-29 22:08:54 发布

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

我以np.save("image_mean.npy", averaged_mean)的形式将numpy数组保存到一个二进制文件中。当我打开文件时,观察到bianry文件的头是“NUMPY V {'descr': '<f8', 'fortran_order': False, 'shape': (3L, 704L, 1248L), }。在

我的问题是NUMPY V指的是什么? 如果我希望它是NUMPY F“NUMPY F {'descr': '<f8', 'fortran_order': False, 'shape': (3L, 704L, 1248L), },那么在np.saveAPI中如何更改?在


Tags: 文件imagenumpyfalsesavenpordermean
1条回答
网友
1楼 · 发布于 2024-04-29 22:08:54

V是头数据的长度(包括空格填充和终止换行)。在

the documentation -

  1. The first 6 bytes are a magic string: exactly “x93NUMPY”.

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

  3. 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.

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

  5. The next HEADER_LEN bytes form the header data describing the array’s format. It is an ASCII string which contains a Python literal expression of a dictionary. It is terminated by a newline (‘n’) and padded with spaces (‘x20’) to make the total length of the magic string + 4 + HEADER_LEN be evenly divisible by 16 for alignment purposes.

示例中的头数据(包括一个换行符)的长度为71。这使得magic_string + 4 + HEADER_LEN等于81,它不能被16整除,所以下一个可整除的数字是96,因此头数据被15个空格填充,这样总长度就等于96。这使得头的长度为-86。它是V。在

>>> chr(86)
'V'

相关问题 更多 >