I want to save the output of my Python program into a text file to use it in C for some reasons, I don't know how should I do it. The code is:
import networkx as nx
import numpy as np
t_start=0;t_end=1;dt=0.1
tpoints=np.arange(t_start,t_end,dt)
G = nx.grid_2d_graph(20,20, periodic=False, create_using=None)
adj_matrix=nx.adjacency_matrix(G)
print(adj_matrix.todense())
If the number of nodes were less than 20 (like 10 or lower) the output would be:
[[0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0]
[1 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0]
[0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 0]
[0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0]
[1 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0]
[0 1 0 0 1 0 1 0 0 1 0 0 0 0 0 0]
[0 0 1 0 0 1 0 1 0 0 1 0 0 0 0 0]
[0 0 0 1 0 0 1 0 0 0 0 1 0 0 0 0]
[0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0]
[0 0 0 0 0 1 0 0 1 0 1 0 0 1 0 0]
[0 0 0 0 0 0 1 0 0 1 0 1 0 0 1 0]
[0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 1]
[0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0]
[0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 0]
[0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1]
[0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0]]
But when the number of nodes increase, the output is like this:
[[0 1 0 ... 0 0 0]
[1 0 1 ... 0 0 0]
[0 1 0 ... 0 0 0]
...
[0 0 0 ... 0 1 0]
[0 0 0 ... 1 0 1]
[0 0 0 ... 0 1 0]]
And so I can't copy it manually to a text file. So I need a command to write this matrix completely to a text file. Thanks for your answers.