0

I've this error message TypeError: 'numpy.float64' object is not iterable when y execute my .py.

It occur in:

file=open("results.txt","a")
    for i in ConcatRPH:
        for j in i :
        file.write(j)
    file.write("\n")
file.close()

ConcatRPH is a large array about 2 million line by 3 column which containt floats like -0.00161894927736417and i need to write them in a txt file. I don't know why I have this error ... Do you have any idea ?

hpaulj
  • 221,503
  • 14
  • 230
  • 353
Arnaud
  • 13
  • 1
  • Are you sure that you've got the indentation correct? And perhaps [this](https://stackoverflow.com/questions/9565426/saving-numpy-array-to-txt-file-row-wise) post discusses what you want. – J...S Mar 13 '19 at 10:36

1 Answers1

0

The only possible reason is that ConcatRPH does not have the shape you think it has. So, most likely, the i you get from for i in ConcatRPH is a float, and you get an error on the following line. Print i to make sure.

However, if you really want to store a table to a text file (not doing it for practice), better use numpy.savetxt.

blue_note
  • 27,712
  • 9
  • 72
  • 90