import networkx as nx import scipy.io import numpy as np graphs = [] indexes = [(1,12), (2,6),(3,4),(4,3),(6,2),(12,1)] for tupp in indexes: graphs.append(nx.grid_2d_graph(tupp[0], tupp[1])) for g in range(len(indexes)): curr_graph = nx.to_numpy_array(graphs[g]) curr_graph_att = np.ones((len(curr_graph), 60)) scipy.io.savemat('produced_graphs/testgraph_{}_{}__.txt'.format(indexes[g][0], indexes[g][1], g), {'data': curr_graph}) scipy.io.savemat('produced_graphs/testgraph_{}_{}__.usr'.format(indexes[g][0], indexes[g][1], g), {'attributes': curr_graph_att}) print(graphs)