I need someones opinion on how to extract and save the array data in one output file from this script. Files3 contain set number dataset files in Latitude, Longitude and Rainfall. Each dataset is arranged just like this:
Latitude Longitude Rainfall
-5.000 95.000 0.000
-4.900 95.000 0.000
-4.800 95.000 0.000
-4.700 95.000 0.000
-4.600 95.000 0.000
Objective : How to save all the dataset especially the rainfall and saved in file into this array. The problem is the output only picked up only one dataset.
Latitude Longitude Rainfall1 Rainfall2 Rainfall3 Rainfall4 . .
-5.000 95.000 0.000 0.000 0.000 0.000
-4.900 95.000 5.7 0 0.000 0.000 23.9
-4.800 95.000 0.000 10.4 0.000 0.000
-4.700 95.000 0.000 0.000 0.000 0.000
-4.600 95.000 0.000 0.000 0.000 0.000
The halfway script that I am using is just as follows:
import numpy as np
import matplotlib.pyplot as plt
files=np.loadtxt('files3',dtype=str)
for x in files:
data=np.loadtxt(x)
lat=data[:,0]
lon=data[:,1]
rain=data[:,2]
rain=[lat,lon,rain]
data1=np.array(rain)
data1=data1.T
np.savetxt( 'build-mean1.dat2',data1,fmt='%9.3f')
np.savetxtinside the loop, so at each iteration it will just replace the file with a new dataset, and you will end up only with the last one in the file