code: def am_to_im(am):
      r
      if am.shape[0] != am.shape[1]:
          raise Exception('Adjacency matrices must be square')
      if am.format != 'coo':
          am = am.tocoo(copy=False)
      conn = sp.vstack((am.row, am.col)).T
      row = conn[:, 0]
      data = am.data
      col = sp.arange(sp.size(am.data))
      if istriangular(am):
          row = sp.append(row, conn[:, 1])
          data = sp.append(data, data)
          col = sp.append(col, col)
      im = sprs.coo.coo_matrix((data, (row, col)), (row.max()+1, col.max()+1))
      return im
docs: r"""
      Convert an adjacency matrix into an incidence matrix