triples = []
for i in range(G.shape[0]):
    row = G[(i), :]
J = np.nonzero(row)[0].tolist()
for t1, t2 in itertools.combinations(J, 2):
    triples.append((i, t1, t2))
print(triples)
Python, Scipy: Building triplets using large adjacency matrix