Advertisement
dan-masek

Untitled

Oct 29th, 2019
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. import numpy as np
  2.  
  3. MSD_list = [(0,0,0),(0.5,1,0),(1,2,0),(0,0,1),(2,1,1),(4,2,1)]
  4. MSD_traces = [[] for x in range(2)]
  5.  
  6. #   MSD_traces is a list that collects the data later on in a nested loop.
  7.  
  8. MSD_array = np.zeros(len(MSD_list),dtype = [('d_space', 'f8'),('d_time', 'i4'), ('traceID', 'i4')])
  9. MSD_array[:] = MSD_list
  10.  
  11. #   Now I want to go into the array, select all the data that has a common traceID,
  12. #   then I select a subarray with same timelag and go into a second inner loop...
  13.  
  14. for i in range(2): #2 = the amount of unique traces in my example
  15.  
  16.     trace_view = MSD_array[MSD_array['traceID']==i]
  17.     for k in range(np.max(trace_view['d_time'])+1):
  18.         #iterating from d_time 0 to the maximum d_time in that trace
  19.  
  20.         time_view = trace_view[trace_view['d_time']==k]
  21.         if time_view['d_space'].size:
  22.             #checking for empty array where np.mean() yields error
  23.  
  24.             msd_mean = np.mean(time_view['d_space'])
  25.             MSD_traces[i].append((msd_mean, k))
  26.  
  27. print(MSD_traces[0])
  28. print(MSD_traces[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement