Created
December 12, 2015 23:04
-
-
Save d-v-b/750ee835ae57a2cc6abc to your computer and use it in GitHub Desktop.
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
# 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