Save float array to a txt file

0

After saving array in txt I want to be able to work with each of the values doing all the mathematical manipulations, but the way I'm saving I'm not getting it. Can anyone help me.

import numpy as np

xold = np.random.rand()
N = 3000

x0 = np.empty((N))

for k in range(N):
    x_new = 4*xold*(1 - xold)
    xold = x_new
    x0[k] = x_new

comp = len(x0)
aux = x0 + 0.25*np.std(x0)*np.random.rand(1,comp)

x2 = aux[0]

x3 = x2[1000:]
#X = x3[:-1]
A = x3[:-1].transpose()
D = x3[1:]

#-------- SALVAR EM TXT ---------------|
np.savetxt('A.txt', A, newline='\n')

with open('A.txt','r') as arq:
    aux = arq.read()

X = np.array([aux])
print(X[0])
print(type(X[0]))
print(X.shape)
    
asked by anonymous 11.11.2018 / 15:34

1 answer

1

If you saved with numpy.savetxt , you should use numpy.loadtxt to load:

np.savetxt('A.txt', A, newline='\n')

Then ...

A = np.loadtxt('A.txt') 
    
11.11.2018 / 19:42