I have a 1D numpy array of datetime objects, and I would like to grab all the objects which have a certain month. I can do this by iterating over the entire array:
new_times = []
for time in times:
if time.month == 1:
new_times.append(time)
but this isn't very efficient and doesn't seem very pythonic. If this was an array of integer months, I could do something like
arr = np.array([1,1,2,3,4,5,6,1,7,4,8,1])
new_arr = arr[np.where(arr == 1)]
but this method doesn't work when calling attributes of the array's objects. Is there a nice way of searching for all numpy array elements which have a certain object attribute?