code: def save_npz(file, matrix, compressed=True):
      """Save a sparse matrix or array to a file using ``.npz`` format.
  
      Parameters
      ----------
      file : str or file-like object
          Either the file name (string) or an open file (file-like object)
          where the data will be saved. If file is a string, the ``.npz``
          extension will be appended to the file name if it is not already
          there.
      matrix: spmatrix or sparray
          The sparse matrix or array to save.
          Supported formats: ``csc``, ``csr``, ``bsr``, ``dia`` or ``coo``.
      compressed : bool, optional
          Allow compressing the file. Default: True
  
      See Also
      --------
      scipy.sparse.load_npz: Load a sparse matrix from a file using ``.npz`` format.
      numpy.savez: Save several arrays into a ``.npz`` archive.
      numpy.savez_compressed : Save several arrays into a compressed ``.npz`` archive.
  
      Examples
      --------
      Store sparse matrix to disk, and load it again:
  
      >>> import numpy as np
      >>> import scipy as sp
      >>> sparse_matrix = sp.sparse.csc_matrix([[0, 0, 3], [4, 0, 0]])
      >>> sparse_matrix
      <2x3 sparse matrix of type '<class 'numpy.int64'>'
         with 2 stored elements in Compressed Sparse Column format>
      >>> sparse_matrix.toarray()
      array([[0, 0, 3],
             [4, 0, 0]], dtype=int64)
  
      >>> sp.sparse.save_npz('/tmp/sparse_matrix.npz', sparse_matrix)
      >>> sparse_matrix = sp.sparse.load_npz('/tmp/sparse_matrix.npz')
  
      >>> sparse_matrix
      <2x3 sparse matrix of type '<class 'numpy.int64'>'
         with 2 stored elements in Compressed Sparse Column format>
      >>> sparse_matrix.toarray()
      array([[0, 0, 3],
             [4, 0, 0]], dtype=int64)
      """
      arrays_dict = {}
      if matrix.format in ("csc", "csr", "bsr"):
          arrays_dict.update(
              indices=matrix.indices, indptr=matrix.indptr
          )
      elif matrix.format == "dia":
          arrays_dict.update(offsets=matrix.offsets)
      elif matrix.format == "coo":
          arrays_dict.update(row=matrix.row, col=matrix.col)
      else:
          msg = f"Save is not implemented for sparse matrix of format {matrix.format}."
          raise NotImplementedError(msg)
      arrays_dict.update(
          format=matrix.format.encode("ascii"),
          shape=matrix.shape,
          data=matrix.data,
      )
      if isinstance(matrix, sp.sparse.sparray):
          arrays_dict.update(_is_array=True)
      if compressed:
          np.savez_compressed(file, **arrays_dict)
      else:
          np.savez(file, **arrays_dict)
  
label_desc: Use image node_id 1 for calling a global function with example usage: save_npz(file, matrix, compressed) without return types