I am struggeling with a problem since a few days. I have 100 different time folders, every folder contains 11 sensor1.dat, sensor2.dat etc.. files.
Example for sensor1.dat
x1,x2,x3
1,2,3
4,5,6
7,8,9
I am trying to loop all over the timefolders and load in for every timestep the last row of the sensor files
Results could be a nested list: Outer list contains the time data - Inner List for every time data all sensor_data, which means here: Outer List 100 rows, inner list 11 rows for each outer row.
Therefore I tried following:
def getData():
for TIME in TIMES:
cd_string = TIME
cd_string = string.replace(cd_string,'\n','')
os.chdir(cd_string)
print(TIME)
i_sensors=11
data=[]
for i in xrange(1,i_sensors+1):
#print i
sensor_string='../../sets/'+cd_string+'/w_z_sensor_'+str(i)+'_U.dat'
data_input = np.genfromtxt(sensor_string, delimiter="," , skip_header=1)
data.append(data_input[-1,:])
os.chdir('../')
return data
######MAIN####
TIMES = os.popen("ls -d 0.31* ").readlines()
zw=[[]] #*len(TIMES)
for i in xrange(0,len(TIMES)):
zw[i].append(getData())
The function getData works fine and I get all the data I need for the sensor files for each time step,
The problem is the main part. Here I amt trying to append the sensor data for every time folder. This does not work. With the uncommented z=[[]]*len(TIMES) it just only copy the data in 100 rows
Where is my problem?
Any advice and thanks in advance?