def write_sparse(self, arr):
A = arr.tocsc()  <EOL>A.sort_indices()     <EOL>is_complex = (A.dtype.kind == '<STR_LIT:c>')<EOL>is_logical = (A.dtype.kind == '<STR_LIT:b>')<EOL>nz = A.nnz<EOL>self.write_header(matdims(arr, self.oned_as),<EOL>mxSPARSE_CLASS,<EOL>is_complex=is_complex,<EOL>is_logical=is_logical,<EOL>nzmax=nz)<EOL>self.write_element(A.indices.astype('<STR_LIT>'))<EOL>self.write_element(A.indptr.astype('<STR_LIT>'))<EOL>self.write_element(A.data.real)<EOL>if is_complex:<EOL><INDENT>self.write_element(A.data.imag)<EOL><DEDENT>
Sparse matrices are 2D