7
I have tried several things and I still can not grasp what the problem of my code, is a simple code. With numpy i place txt values in the array of arrays and want to make some copies to two other lists, mensagem
and no
.
import numpy as dados
i=0
filename = input("Entre com o arquivo de dados:")
entrada = dados.genfromtxt(filename, delimiter=" ", dtype=int)
mensagem = dados.zeros((300,1))
no = dados.zeros((300,1))
for x in range(0,entrada.shape[0]):
if(entrada[x][0] in mensagem):
print("JÁ")
else:
mensagem[i]=(entrada[x][0])
no[i]=(entrada[x][1])
i=i+1
arquivo = open('mensagem.txt', 'w')
arquivo1 = open('no.txt', 'w')
for x in range(0,300):
arquivo.write(str(mensagem[x]))
arquivo.write('\n')
for x in range(0,300):
arquivo1.write(str(no[x]))
arquivo1.write('\n')
I’ve tried to change dtype
for int
, float
, None
.
Always the list no
receives in a few positions the correct value, and the rest fills with number 1.
It is worth saying that my data file that fills the list is of format:
2.94946 14 5
2.92017 14 8
2.9751 14 19
2.97217 14 17
2.88794 14 2
2.95166 14 13
2.87769 14 12
2.95166 14 5
2.95166 14 7
2.88354 14 21
2.94653 12 24
2.99927 12 25
and has more than 300 thousand lines.
Any suggestions, or noticed anything wrong?
your file is bounded by spaces or tabs? the lines even start with spaces like in your example?
– sergiopereira
Hello sergiopereira, yes, are fired by tabs...2.946TAB14TAB5
– Alexandra Silva
change delimiter to t made no difference :/
– Alexandra Silva
I think I found your problem. See my answer.
– sergiopereira