MCPcopy Create free account
hub / github.com/numpy/numpy / open_memmap

Function open_memmap

numpy/lib/format.py:844–948  ·  view source on GitHub ↗

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 or path-like The name of the file on disk. This may *not* be a file-like object. mode : str, optional The

(filename, mode='r+', dtype=None, shape=None,
                fortran_order=False, version=None, *,
                max_header_size=_MAX_HEADER_SIZE)

Source from the content-addressed store, hash-verified

842
843
844def open_memmap(filename, mode='r+', dtype=None, shape=None,
845 fortran_order=False, version=None, *,
846 max_header_size=_MAX_HEADER_SIZE):
847 """
848 Open a .npy file as a memory-mapped array.
849
850 This may be used to read an existing file or create a new one.
851
852 Parameters
853 ----------
854 filename : str or path-like
855 The name of the file on disk. This may *not* be a file-like
856 object.
857 mode : str, optional
858 The mode in which to open the file; the default is 'r+'. In
859 addition to the standard file modes, 'c' is also accepted to mean
860 "copy on write." See `memmap` for the available mode strings.
861 dtype : data-type, optional
862 The data type of the array if we are creating a new file in "write"
863 mode, if not, `dtype` is ignored. The default value is None, which
864 results in a data-type of `float64`.
865 shape : tuple of int
866 The shape of the array if we are creating a new file in "write"
867 mode, in which case this parameter is required. Otherwise, this
868 parameter is ignored and is thus optional.
869 fortran_order : bool, optional
870 Whether the array should be Fortran-contiguous (True) or
871 C-contiguous (False, the default) if we are creating a new file in
872 "write" mode.
873 version : tuple of int (major, minor) or None
874 If the mode is a "write" mode, then this is the version of the file
875 format used to create the file. None means use the oldest
876 supported version that is able to store the data. Default: None
877 max_header_size : int, optional
878 Maximum allowed size of the header. Large headers may not be safe
879 to load securely and thus require explicitly passing a larger value.
880 See :py:func:`ast.literal_eval()` for details.
881
882 Returns
883 -------
884 marray : memmap
885 The memory-mapped array.
886
887 Raises
888 ------
889 ValueError
890 If the data or the mode is invalid.
891 OSError
892 If the file is not found or cannot be opened correctly.
893
894 See Also
895 --------
896 numpy.memmap
897
898 """
899 if isfileobj(filename):
900 raise ValueError("Filename must be a string or a path-like object."
901 " Memmap cannot use existing file handles.")

Callers

nothing calls this directly

Calls 8

isfileobjFunction · 0.90
_check_versionFunction · 0.85
dtype_to_descrFunction · 0.85
openFunction · 0.85
_write_array_headerFunction · 0.85
read_magicFunction · 0.85
_read_array_headerFunction · 0.85
dtypeMethod · 0.45

Tested by

no test coverage detected