I have a nxm numpy array that either has positive values with 8 decimal points like 0.02113342 or NoValue data that is -9999. I am using the line below to make a text file from the numpy array
numpy.savetxt("result.asc", Numpy_Array, fmt="%.8f")#2D array to ASCII
However, I will have -9999.00000000 instead of -9999. I open the file and replace those numbers with -9999 using the following code:
with file("result.asc", 'r') as original:
data = original.read()
new = data.replace(str(-9999)+".00000000", str(-9999))
with file("result.asc", 'w') as modified:
modified.write(new)
Is there a more elegant way to write -9999 rather than -9999.00000000 from the beginning instead of opening the whole file again and replacing them?
-9999.00000000persist?