Saves float array in a txt file

Asked

Viewed 1,271 times

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 q I am saving I am not getting. Someone can 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)

1 answer

1


If you saved with numpy.savetxt, must use numpy.loadtxt to carry:

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

Afterward...

A = np.loadtxt('A.txt') 
  • That’s what I wanted to do. Thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.