for cid, kid, val in q.all():
if cid not in row_index:
row_index[cid] = len(row_index)
if kid not in col_index:
col_index[kid] = len(col_index)
X[row_index[cid], col_index[kid]] = val
// Return as an AnnotationMatrix
return self.matrix_cls(X, candidate_set=candidate_set, key_set=key_set)
After Change
// Iteratively construct row index and output sparse matrix
cid_to_row = {}
row_to_cid = {}
for cid, kid, val in q.all():
if cid not in cid_to_row:
i = len(cid_to_row)