Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- MSD_list = [(0,0,0),(0.5,1,0),(1,2,0),(0,0,1),(2,1,1),(4,2,1)]
- MSD_traces = [[] for x in range(2)]
- # MSD_traces is a list that collects the data later on in a nested loop.
- MSD_array = np.zeros(len(MSD_list),dtype = [('d_space', 'f8'),('d_time', 'i4'), ('traceID', 'i4')])
- MSD_array[:] = MSD_list
- # Now I want to go into the array, select all the data that has a common traceID,
- # then I select a subarray with same timelag and go into a second inner loop...
- for i in range(2): #2 = the amount of unique traces in my example
- trace_view = MSD_array[MSD_array['traceID']==i]
- for k in range(np.max(trace_view['d_time'])+1):
- #iterating from d_time 0 to the maximum d_time in that trace
- time_view = trace_view[trace_view['d_time']==k]
- if time_view['d_space'].size:
- #checking for empty array where np.mean() yields error
- msd_mean = np.mean(time_view['d_space'])
- MSD_traces[i].append((msd_mean, k))
- print(MSD_traces[0])
- print(MSD_traces[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement