docstr: Sparse matrices are 2D
  
  See docstring for VarReader4.read_sparse_array
docstr_tok: ["Sparse","matrices","are","2D","See","docstring","for","VarReader4.read_sparse_array"]
code: def write_sparse(self, arr, name):
      """Sparse matrices are 2D
  
      See docstring for VarReader4.read_sparse_array
      """
      A = arr.tocoo()  # convert to sparse COO format (ijv)
      imagf = A.dtype.kind == "c"
      ijv = np.zeros((A.nnz + 1, 3 + imagf), dtype="f8")
      ijv[:-1, 0] = A.row
      ijv[:-1, 1] = A.col
      ijv[:-1, 0:2] += 1  # 1 based indexing
      if imagf:
          ijv[:-1, 2] = A.data.real
          ijv[:-1, 3] = A.data.imag
      else:
          ijv[:-1, 2] = A.data
      ijv[-1, 0:2] = A.shape
      self.write_header(name, ijv.shape, P=miDOUBLE, T=mxSPARSE_CLASS)
      self.write_bytes(ijv)
  
imports: from __future__ import division, print_function, absolute_import
  import sys
  import warnings
  import numpy
  from numpy.compat import asbytes, asstr
  import scipy.sparse
  from scipy._lib.six import string_types
  from .miobase import MatFileReader, docfiller, matdims, read_dtype, convert_dtypes, arr_to_chars, arr_dtype_number
  from .mio_utils import squeeze_element, chars_to_strings
  from functools import reduce
label_desc: Use image node_id 8 for calling the VarWriter4 obj's underlying member method code with example usage: obj.write_sparse(arr, name) without return types