>>> print numpy.lib.format.open_memmap.__doc__
"""
Open a .npy file as a memory-mapped array.
This may be used to read an existing file or create a new one.
Parameters
filename : str
The name of the file on disk. This may not be a filelike object.
mode : str, optional
The mode to open the file with. In addition to the standard file modes,
'c' is also accepted to mean "copy on write". See `numpy.memmap` for
the available mode strings.
dtype : dtype, optional
The data type of the array if we are creating a new file in "write"
mode.
shape : tuple of int, optional
The shape of the array if we are creating a new file in "write"
mode.
fortran_order : bool, optional
Whether the array should be Fortran-contiguous (True) or
C-contiguous (False) if we are creating a new file in "write" mode.
version : tuple of int (major, minor)
If the mode is a "write" mode, then this is the version of the file
format used to create the file.
Returns
-
marray : numpy.memmap
The memory-mapped array.
Raises
ValueError
If the data or the mode is invalid.
IOError
If the file is not found or cannot be opened correctly.
See Also
numpy.memmap
"""
通常,应该使用
np.memmap()
来使用数组而不加载到RAM上。在numpy docs中,“内存映射文件用于访问磁盘上大文件的小部分,而无需将整个文件读入内存。”用法示例:
但是,由于您的文件已经存储为.npy文件,我偶然发现了
np.lib.format.open_memmap()
,它创建或加载内存映射的.npy文件。在用法如下所示,与您使用的相同np.memmap公司():
^{pr2}$以下是第二个函数的文档(来自this answer):
相关问题 更多 >
编程相关推荐