def _buildAB(lap_sparse, labels):
 labels = labels[(labels >= 0)]
 indices = np.arange(labels.size)
 unlabeled_indices = indices[(labels == 0)]
 seeds_indices = indices[(labels > 0)]
 B = lap_sparse[unlabeled_indices][:, seeds_indices]
 lap_sparse = lap_sparse[unlabeled_indices][:, unlabeled_indices]
 nlabels = labels.max()
 rhs = []
 for lab in range(1, (nlabels + 1)):
  mask = (labels[seeds_indices] == lab)
  fs = sparse.csr_matrix(mask)
  fs = fs.transpose()
  rhs.append((B * fs))
 return (lap_sparse, rhs)

def _buildAB ( lap_sparse , labels ) : labels = labels [ ( labels >= 0 ) ] indices = np . arange ( labels . size ) unlabeled_indices = indices [ ( labels == 0 ) ] seeds_indices = indices [ ( labels > 0 ) ] B = lap_sparse [ unlabeled_indices ] [ : , seeds_indices ] lap_sparse = lap_sparse [ unlabeled_indices ] [ : , unlabeled_indices ] nlabels = labels . max ( ) rhs = [ ] for lab in range ( 1 , ( nlabels + 1 ) ) : mask = ( labels [ seeds_indices ] == lab ) fs = sparse . csr_matrix ( mask ) fs = fs . transpose ( ) rhs . append ( ( B * fs ) ) return ( lap_sparse , rhs )
build the matrix a and rhs b of the linear system to solve .