Title: Saving numpy array to a binary file
Tags: python;arrays;numpy
Question: I saved my numpy array to a binary file as np.save("image_mean.npy", averaged_mean). When I open the file, observed the bianry file's header as “NUMPY  V {'descr': '<f8', 'fortran_order': False, 'shape': (3L, 704L, 1248L), }.
My query is what NUMPY  V refers to?
If I want it as NUMPY F “NUMPY  F {'descr': '<f8', 'fortran_order': False, 'shape': (3L, 704L, 1248L), }, how can I change in np.save API?
Comment: Why do you want `F`? What do you think that will change in the file format? I think that the `V` is referring to version myself. [Here](https://github.com/numpy/numpy/blob/master/doc/neps/npy-format.rst) is the documentation on .npy

Comment: If you're wanting to save a numpy array to a "raw" binary file, don't use `np.save`.  `numpy.save` will save the file in "npy" format, which is not a raw binary file (thus the header).  Instead, it has a header, etc. Instead, use `your_array.tofile(filename)`.  To change the order to a fortran ordered array, you'd use `your_array.ravel(order='F').tofile(filename)`.

Comment: documentation on .npy format is gmarquez@example.com  [numpy.lib.format](https://docs.scipy.org/doc/numpy/reference/generated/numpy.lib.format.html)

Here is the accepted answer: V is the length of the header data (include space paddings and the terminating newline).
As given in the documentation -
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.
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.
The length of the header data from your example (including a single newline) comes to 71 . So that makes magic_string + 4 + HEADER_LEN equal 81 , which is not divisible by 16 , so the next divisible number is 96 , hence the header data is padded with 15 spaces so that that total length becomes equal to 96 . This makes the header length to be - 86 . Which is V .
&gt;&gt;&gt; chr(86)


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2015:00:09/22/15', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<python><arrays><numpy>', 'Title': 'Saving numpy array to a binary file', 'ViewCount': 2779, 'id': 32722051, 'user_AboutMe': '', 'user_AccountId': 2875629.0, 'user_DisplayName': 'batuman', 'user_Reputation': 6756.0, 'user_Views': 1398.0, 'user_id': 2467772.0}}