Create a memory-map to an array stored in a *binary* file on disk. Memory-mapped files are used for accessing small segments of large files on disk, without reading the entire file into memory. NumPy's memmap's are array-like objects. This differs from Python's ``mmap`` module, wh
| 22 | |
| 23 | @set_module('numpy') |
| 24 | class memmap(ndarray): |
| 25 | """Create a memory-map to an array stored in a *binary* file on disk. |
| 26 | |
| 27 | Memory-mapped files are used for accessing small segments of large files |
| 28 | on disk, without reading the entire file into memory. NumPy's |
| 29 | memmap's are array-like objects. This differs from Python's ``mmap`` |
| 30 | module, which uses file-like objects. |
| 31 | |
| 32 | This subclass of ndarray has some unpleasant interactions with |
| 33 | some operations, because it doesn't quite fit properly as a subclass. |
| 34 | An alternative to using this subclass is to create the ``mmap`` |
| 35 | object yourself, then create an ndarray with ndarray.__new__ directly, |
| 36 | passing the object created in its 'buffer=' parameter. |
| 37 | |
| 38 | This class may at some point be turned into a factory function |
| 39 | which returns a view into an mmap buffer. |
| 40 | |
| 41 | Flush the memmap instance to write the changes to the file. Currently there |
| 42 | is no API to close the underlying ``mmap``. It is tricky to ensure the |
| 43 | resource is actually closed, since it may be shared between different |
| 44 | memmap instances. |
| 45 | |
| 46 | |
| 47 | Parameters |
| 48 | ---------- |
| 49 | filename : str, file-like object, or pathlib.Path instance |
| 50 | The file name or file object to be used as the array data buffer. |
| 51 | dtype : data-type, optional |
| 52 | The data-type used to interpret the file contents. |
| 53 | Default is `uint8`. |
| 54 | mode : {'r+', 'r', 'w+', 'c'}, optional |
| 55 | The file is opened in this mode: |
| 56 | |
| 57 | +------+-------------------------------------------------------------+ |
| 58 | | 'r' | Open existing file for reading only. | |
| 59 | +------+-------------------------------------------------------------+ |
| 60 | | 'r+' | Open existing file for reading and writing. | |
| 61 | +------+-------------------------------------------------------------+ |
| 62 | | 'w+' | Create or overwrite existing file for reading and writing. | |
| 63 | | | If ``mode == 'w+'`` then `shape` must also be specified. | |
| 64 | +------+-------------------------------------------------------------+ |
| 65 | | 'c' | Copy-on-write: assignments affect data in memory, but | |
| 66 | | | changes are not saved to disk. The file on disk is | |
| 67 | | | read-only. | |
| 68 | +------+-------------------------------------------------------------+ |
| 69 | |
| 70 | Default is 'r+'. |
| 71 | offset : int, optional |
| 72 | In the file, array data starts at this offset. Since `offset` is |
| 73 | measured in bytes, it should normally be a multiple of the byte-size |
| 74 | of `dtype`. When ``mode != 'r'``, even positive offsets beyond end of |
| 75 | file are valid; The file will be extended to accommodate the |
| 76 | additional data. By default, ``memmap`` will start at the beginning of |
| 77 | the file, even if ``filename`` is a file pointer ``fp`` and |
| 78 | ``fp.tell() != 0``. |
| 79 | shape : int or sequence of ints, optional |
| 80 | The desired shape of the array. If ``mode == 'r'`` and the number |
| 81 | of remaining bytes after `offset` is not a multiple of the byte-size |
no outgoing calls
searching dependent graphs…