parameters: (file, mmap_mode=None)
docstring: Load an array(s) or pickled objects from .npy, .npz, or pickled files.
  
      Parameters
      ----------
      file : file-like object or string
          The file to read. Compressed files with the filename extension
          ``.gz`` are acceptable. File-like objects must support the
          ``seek()`` and ``read()`` methods. Pickled files require that the
          file-like object support the ``readline()`` method as well.
      mmap_mode : {None, 'r+', 'r', 'w+', 'c'}, optional
          If not None, then memory-map the file, using the given mode (see
          `numpy.memmap` for a detailed description of the modes).  A
          memory-mapped array is kept on disk. However, it can be accessed
          and sliced like any ndarray.  Memory mapping is especially useful
          for accessing small fragments of large files without reading the
          entire file into memory.
  
      Returns
      -------
      result : array, tuple, dict, etc.
          Data stored in the file. For ``.npz`` files, the returned instance
          of NpzFile class must be closed to avoid leaking file descriptors.
  
      Raises
      ------
      IOError
          If the input file does not exist or cannot be read.
  
      See Also
      --------
      save, savez, savez_compressed, loadtxt
      memmap : Create a memory-map to an array stored in a file on disk.
  
      Notes
      -----
      - If the file contains pickle data, then whatever object is stored
        in the pickle is returned.
      - If the file is a ``.npy`` file, then a single array is returned.
      - If the file is a ``.npz`` file, then a dictionary-like object is
        returned, containing ``{filename: array}`` key-value pairs, one for
        each file in the archive.
      - If the file is a ``.npz`` file, the returned value supports the
        context manager protocol in a similar fashion to the open function::
  
          with load('foo.npz') as data:
              a = data['a']
  
        The underlying file descriptor is closed when exiting the 'with'
        block.
  
      Examples
      --------
      Store data to disk, and load it again:
  
      >>> np.save('/tmp/123', np.array([[1, 2, 3], [4, 5, 6]]))
      >>> np.load('/tmp/123.npy')
      array([[1, 2, 3],
             [4, 5, 6]])
  
      Store compressed data to disk, and load it again:
  
      >>> a=np.array([[1, 2, 3], [4, 5, 6]])
      >>> b=np.array([1, 2])
      >>> np.savez('/tmp/123.npz', a=a, b=b)
      >>> data = np.load('/tmp/123.npz')
      >>> data['a']
      array([[1, 2, 3],
             [4, 5, 6]])
      >>> data['b']
      array([1, 2])
      >>> data.close()
  
      Mem-map the stored array, and then access the second row
      directly from disk:
  
      >>> X = np.load('/tmp/123.npy', mmap_mode='r')
      >>> X[1, :]
      memmap([4, 5, 6])
docstring_summary: Load an array(s) or pickled objects from .npy, .npz, or pickled files.
docstring_tokens: Load an array ( s ) or pickled objects from . npy . npz or pickled files .
function: def load(file, mmap_mode=None):
      """
      Load an array(s) or pickled objects from .npy, .npz, or pickled files.
  
      Parameters
      ----------
      file : file-like object or string
          The file to read. Compressed files with the filename extension
          ``.gz`` are acceptable. File-like objects must support the
          ``seek()`` and ``read()`` methods. Pickled files require that the
          file-like object support the ``readline()`` method as well.
      mmap_mode : {None, 'r+', 'r', 'w+', 'c'}, optional
          If not None, then memory-map the file, using the given mode (see
          `numpy.memmap` for a detailed description of the modes).  A
          memory-mapped array is kept on disk. However, it can be accessed
          and sliced like any ndarray.  Memory mapping is especially useful
          for accessing small fragments of large files without reading the
          entire file into memory.
  
      Returns
      -------
      result : array, tuple, dict, etc.
          Data stored in the file. For ``.npz`` files, the returned instance
          of NpzFile class must be closed to avoid leaking file descriptors.
  
      Raises
      ------
      IOError
          If the input file does not exist or cannot be read.
  
      See Also
      --------
      save, savez, savez_compressed, loadtxt
      memmap : Create a memory-map to an array stored in a file on disk.
  
      Notes
      -----
      - If the file contains pickle data, then whatever object is stored
        in the pickle is returned.
      - If the file is a ``.npy`` file, then a single array is returned.
      - If the file is a ``.npz`` file, then a dictionary-like object is
        returned, containing ``{filename: array}`` key-value pairs, one for
        each file in the archive.
      - If the file is a ``.npz`` file, the returned value supports the
        context manager protocol in a similar fashion to the open function::
  
          with load('foo.npz') as data:
              a = data['a']
  
        The underlying file descriptor is closed when exiting the 'with'
        block.
  
      Examples
      --------
      Store data to disk, and load it again:
  
      >>> np.save('/tmp/123', np.array([[1, 2, 3], [4, 5, 6]]))
      >>> np.load('/tmp/123.npy')
      array([[1, 2, 3],
             [4, 5, 6]])
  
      Store compressed data to disk, and load it again:
  
      >>> a=np.array([[1, 2, 3], [4, 5, 6]])
      >>> b=np.array([1, 2])
      >>> np.savez('/tmp/123.npz', a=a, b=b)
      >>> data = np.load('/tmp/123.npz')
      >>> data['a']
      array([[1, 2, 3],
             [4, 5, 6]])
      >>> data['b']
      array([1, 2])
      >>> data.close()
  
      Mem-map the stored array, and then access the second row
      directly from disk:
  
      >>> X = np.load('/tmp/123.npy', mmap_mode='r')
      >>> X[1, :]
      memmap([4, 5, 6])
  
      """
      import gzip
  
      own_fid = False
      if isinstance(file, basestring):
          fid = open(file, "rb")
          own_fid = True
      elif isinstance(file, gzip.GzipFile):
          fid = seek_gzip_factory(file)
      else:
          fid = file
  
      try:
          # Code to distinguish from NumPy binary files and pickles.
          _ZIP_PREFIX = asbytes('PK\x03\x04')
          N = len(format.MAGIC_PREFIX)
          magic = fid.read(N)
          fid.seek(-N, 1) # back-up
          if magic.startswith(_ZIP_PREFIX):
              # zip-file (assume .npz)
              # Transfer file ownership to NpzFile
              tmp = own_fid
              own_fid = False
              return NpzFile(fid, own_fid=tmp)
          elif magic == format.MAGIC_PREFIX:
              # .npy file
              if mmap_mode:
                  return format.open_memmap(file, mode=mmap_mode)
              else:
                  return format.read_array(fid)
          else:
              # Try a pickle
              try:
                  return pickle.load(fid)
              except:
                  raise IOError(
                      "Failed to interpret file %s as a pickle" % repr(file))
      finally:
          if own_fid:
              fid.close()
function_tokens: def load ( file , mmap_mode = None ) : import gzip own_fid = False if isinstance ( file , basestring ) : fid = open ( file , "rb" ) own_fid = True elif isinstance ( file , gzip . GzipFile ) : fid = seek_gzip_factory ( file ) else : fid = file try : # Code to distinguish from NumPy binary files and pickles. _ZIP_PREFIX = asbytes ( 'PK\x03\x04' ) N = len ( format . MAGIC_PREFIX ) magic = fid . read ( N ) fid . seek ( - N , 1 ) # back-up if magic . startswith ( _ZIP_PREFIX ) : # zip-file (assume .npz) # Transfer file ownership to NpzFile tmp = own_fid own_fid = False return NpzFile ( fid , own_fid = tmp ) elif magic == format . MAGIC_PREFIX : # .npy file if mmap_mode : return format . open_memmap ( file , mode = mmap_mode ) else : return format . read_array ( fid ) else : # Try a pickle try : return pickle . load ( fid ) except : raise IOError ( "Failed to interpret file %s as a pickle" % repr ( file ) ) finally : if own_fid : fid . close ( )