I have a multi-dimensional array of objects, something like:
a = np.array([obj1,obj2,obj3])
The objects are instances of a class which has several attributes. Let's say one of them is heights and one of them is lengths. To get the corresponding multi-dimensional array of lengths and heights I do:
lengths = np.array([obj1.length,obj2.length,obj3.length])
heights = np.array([obj1.height,obj2.height,obj3.height])
This is starting to clutter up my code quite a lot. Is there a more efficient way of doing this? For instance, I had something like
heights = a.height
in mind but obviously it doesn't work because a is an array of my objects and not my object. But is there something similar I can do that is efficient and pythonic? I tried something like
for x in np.nditer(a,flags=['refs_ok']):
print x.length
to see what would happen but it doesn't work because nditer returns a tuple somehow.
Any ideas?