You can vectorize the function:
>>> import numpy >>> >>> class Obj(object): ... def __init__(self, x, y): ... self.x = x ... self.y = y ... >>> arr = numpy.array([Obj(1, 2), Obj(3, 4), Obj(5, 6)]) >>> >>> vectorized_x = numpy.vectorize(lambda obj: obj.x) >>> >>> vectorized_x(arr) array([1, 3, 5])
Although I'm not sure that you should really store an array of NumPy Python objects in the first place. Vectorize is no more efficient than a Python loop. It would be more convenient to store an array of (n + 1) -D, since we could easily extract the contents simply by slicing, which is a native operation, for example.
>>> a = numpy.array([[(1, 2), (3, 4), (5, 6)], [(7, 8), (9, 10), (11, 12)], [(-13, -14), (-15, -16), (-17, -18)]]) >>> a[:,:,0] array([[ 1, 3, 5], [ 7, 9, 11], [-13, -15, -17]]) >>> a[:,:,1] array([[ 2, 4, 6], [ 8, 10, 12], [-14, -16, -18]])