Skip to content

Instantly share code, notes, and snippets.

@d-v-b
Created December 12, 2015 23:04
Show Gist options
  • Save d-v-b/750ee835ae57a2cc6abc to your computer and use it in GitHub Desktop.
Save d-v-b/750ee835ae57a2cc6abc to your computer and use it in GitHub Desktop.
# Convert a list of (k,v) pairs into an array
def kvp_to_array(dims, data, ind=0, baseline=0):
vol = np.zeros(dims,dtype=data[0][1].dtype) + np.array(baseline).astype(data[0][1].dtype)
for k,v in data:
# check if data contains a single value or an iterable
if hasattr(v,'__iter__'):
vol[k] = v[ind]
else:
vol[k] = v
return vol
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment