So i'm working on optimizing some python code by using numpy arrays instead of for each loops. Is there any way to access fields from a class during slicing of a numpy array?
class foo:
the_int = 0
def __init__(self, i):
self.bar = i
one, two = foo(5), foo(10)
ar = array([one, two])
int_array = ar[0:2].the_int
#I want int_array = [5, 10]
If that isn't possible in that manner, how would I efficiently generate my "int_array" variable without using a for each loop to loop through "ar", gather "the_int" from each entry?
Thanks, Kyle