I would like to save a matrix to a file in python and retain the matrix structure in the output file.
For example:
#Program to test the output of an array to a file
import numpy as np
from mpmath import mp,mpf,matrix
# Set precision to 32 digits
mp.dps=32
#Define array
out=matrix(3,2)
for j in range(3):
out[j,0]=mpf(j+1)*mpf('1.73')
out[j,1]=mp.sin(mpf(j))
filout="test_out.txt"
np.savetxt(filout,out,fmt='%32s')
What I get is:
1.73
0.0
3.46
0.8414709848078965066525023216303
5.19
0.90929742682568169539601986591174
But, what I would like is:
1.73 0.0
3.46 0.8414709848078965066525023216303
5.19 0.90929742682568169539601986591174
Has anyone an idea how to do this (I've tried various ways to preserve the matrix structure to no avail)?