Skip to content

Instantly share code, notes, and snippets.

@JelleAalbers
Created February 10, 2016 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JelleAalbers/43a8ea51331d1af1df69 to your computer and use it in GitHub Desktop.
Save JelleAalbers/43a8ea51331d1af1df69 to your computer and use it in GitHub Desktop.
Convert list of simple root objects to numpy array
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