Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1.  
  2. def root_to_numpy(base_object, field_name, attributes):
  3. """Convert objects stored in base_object.field_name to numpy array
  4. Will query attributes for each of the objects in base_object.field_name
  5. No, root_numpy does not do this for you, that's for trees...
  6. """
  7. objects_to_convert = getattr(base_object, field_name)
  8. if not len(objects_to_convert):
  9. return None
  10. return np.array([tuple([getattr(p, pa) for pa in attributes]) for p in objects_to_convert])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement