[Numpy-discussion] optimise operation in array with datetime objects

Pierre GM pgmdevlist at gmail.com
Wed Jan 28 16:25:19 EST 2009


On Jan 28, 2009, at 3:56 PM, Timmie wrote:
> ### this is the loop I would like to optimize:
> ### looping over arrays is considered inefficient.
> ### what could be a better way?
> hours_array = dates_array.copy()
> for i in range(0, dates_array.size):
> 	hours_array[i] = dates_array[i].hour

You could try:
np.fromiter((_.hour for _ in dates_li), dtype=np.int)
or
np.array([_.hour for _ in dates_li], dtype=np.int)




More information about the NumPy-Discussion mailing list