a = lil_matrix((4, 4), dtype=int)
a.A
rows = np.array([1, 3]).reshape(-1, 1)
rows
cols = np.array([0, 2, 3])
a[rows, cols] += np.ones((rows.size, cols.size))
a.A
rows = np.array([0, 1]).reshape(-1, 1)
cols = np.array([1, 2])
a[rows, cols] += np.ones((rows.size, cols.size))
a.A
Building and updating a sparse matrix in python using scipy