I am trying to write a 100x6 numpy array to a data file using
# print array to file
data = open("store.dat", "w")
for j in xrange(len(array)):
data.write(str(array[i]) + "\n")
but when the file writes, it automatically splits the line after 68 characters i.e. 5 columns of a 6 column array. For example, I want to see
[ 35.47842918 21.82382715 3.18277209 0.38992263 1.17862342 0.46170848]
as one of the lines, but am getting
[ 35.47842918 21.82382715 3.18277209 0.38992263 1.17862342
0.46170848]
I've narrowed it down to a problem with str(array[i])
and it deciding to make itself a new line.
Secondly, is there a better way to be going about this? I'm very new to python and know little about properly coding in it. Ultimately, I'm writing out a simulation of stars to later be read by a module that will render the coordinates in VPython. I thought, to avoid the problems of real-time rendering I could just pass a file once the simulation is complete. Is this inefficient? Should I be passing an object instead?
Thank you
Perhaps it would be more convenient to write it using numpy.save
instead?
Alternatively, you can also use:
numpy.array_str(array[i], max_line_width=1000000)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With