def open_memmap(filename, mode='<STR_LIT>', dtype=None, shape=None,<EOL>fortran_order=False, version=None):
if not isinstance(filename, basestring):<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>if '<STR_LIT:w>' in mode:<EOL><INDENT>_check_version(version)<EOL>dtype = numpy.dtype(dtype)<EOL>if dtype.hasobject:<EOL><INDENT>msg = "<STR_LIT>"<EOL>raise ValueError(msg)<EOL><DEDENT>d = dict(<EOL>descr=dtype_to_descr(dtype),<EOL>fortran_order=fortran_order,<EOL>shape=shape,<EOL>)<EOL>fp = open(filename, mode+'<STR_LIT:b>')<EOL>try:<EOL><INDENT>used_ver = _write_array_header(fp, d, version)<EOL>if version != (<NUM_LIT:2>, <NUM_LIT:0>) and used_ver == (<NUM_LIT:2>, <NUM_LIT:0>):<EOL><INDENT>warnings.warn("<STR_LIT>"<EOL>"<STR_LIT>", UserWarning)<EOL><DEDENT>offset = fp.tell()<EOL><DEDENT>finally:<EOL><INDENT>fp.close()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>fp = open(filename, '<STR_LIT:rb>')<EOL>try:<EOL><INDENT>version = read_magic(fp)<EOL>_check_version(version)<EOL>shape, fortran_order, dtype = _read_array_header(fp, version)<EOL>if dtype.hasobject:<EOL><INDENT>msg = "<STR_LIT>"<EOL>raise ValueError(msg)<EOL><DEDENT>offset = fp.tell()<EOL><DEDENT>finally:<EOL><INDENT>fp.close()<EOL><DEDENT><DEDENT>if fortran_order:<EOL><INDENT>order = '<STR_LIT:F>'<EOL><DEDENT>else:<EOL><INDENT>order = '<STR_LIT:C>'<EOL><DEDENT>if mode == '<STR_LIT>':<EOL><INDENT>mode = '<STR_LIT>'<EOL><DEDENT>marray = numpy.memmap(filename, dtype=dtype, shape=shape, order=order,<EOL>mode=mode, offset=offset)<EOL>return marray<EOL>
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 file-like
    object.
mode : str, optional
    The mode in which to open the file; the default is 'r+'.  In
    addition to the standard file modes, 'c' is also accepted to mean
    "copy on write."  See `memmap` for the available mode strings.
dtype : data-type, optional
    The data type of the array if we are creating a new file in "write"
    mode, if not, `dtype` is ignored.  The default value is None, which
    results in a data-type of `float64`.
shape : tuple of int
    The shape of the array if we are creating a new file in "write"
    mode, in which case this parameter is required.  Otherwise, this
    parameter is ignored and is thus optional.
fortran_order : bool, optional
    Whether the array should be Fortran-contiguous (True) or
    C-contiguous (False, the default) if we are creating a new file in
    "write" mode.
version : tuple of int (major, minor) or None
    If the mode is a "write" mode, then this is the version of the file
    format used to create the file.  None means use the oldest
    supported version that is able to store the data.  Default: None

Returns
-------
marray : 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
--------
memmap