Created
February 10, 2016 10:45
-
-
Save JelleAalbers/43a8ea51331d1af1df69 to your computer and use it in GitHub Desktop.
Convert list of simple root objects to numpy array
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
def root_to_numpy(base_object, field_name, attributes): | |
"""Convert objects stored in base_object.field_name to numpy array | |
Will query attributes for each of the objects in base_object.field_name | |
No, root_numpy does not do this for you, that's for trees... | |
""" | |
objects_to_convert = getattr(base_object, field_name) | |
if not len(objects_to_convert): | |
return None | |
return np.array([tuple([getattr(p, pa) for pa in attributes]) for p in objects_to_convert]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment