Created
August 7, 2012 18:56
-
-
Save lukecampbell/3288323 to your computer and use it in GitHub Desktop.
Dont throw this away
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sample = [ | |
{ | |
'time' : [0,1,2,3], | |
'temp' : [0,1,2,3] | |
}, | |
{ | |
'time' : [4,5,6,7], | |
'cond' : [4,5,6,7], | |
}, | |
{ | |
'time' : [0,1,2,3], | |
'temp' : [0,1,2,3] | |
}, | |
{ | |
'time' : [0,1,2,3], | |
'cond' : [0,1,2,3] | |
}, | |
{ | |
'time' : [5,6,7,8], | |
'cond' : [0,1,2,3] | |
}, | |
{ | |
'time' : [5.5, 6, 7], | |
'temp' : [1,2,3] | |
} | |
] | |
def complete_set(msgs): | |
import numpy as np | |
t = list() | |
t = np.unique(np.sort(np.concatenate([msg['time'] for msg in msgs]))) | |
vector_len = t.size | |
solution = np.zeros((3,vector_len)) | |
for msg in msgs: | |
if 'temp' in msg: | |
for time,temp in zip(msg['time'], msg['temp']): | |
index = np.where(t==time)[0] | |
solution[0][index] = time | |
solution[1][index] = temp | |
if 'cond' in msg: | |
for time,cond in zip(msg['time'], msg['cond']): | |
index = np.where(t==time)[0] | |
solution[0][index] = time | |
solution[2][index] = cond | |
return solution |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment