never use todense on sparse matrices they return np.matrix

you should use .toarray although here I would just use ch_connectivity and avoid the creation of x