[Numpy-discussion] optimise operation in array with datetime objects
Pierre GM
pgmdevlist@gmail....
Wed Jan 28 16:49:53 CST 2009
On Jan 28, 2009, at 5:43 PM, Timmie wrote:
>>
>> You could try:
>> np.fromiter((_.hour for _ in dates_li), dtype=np.int)
>> or
>> np.array([_.hour for _ in dates_li], dtype=np.int)
>
> I used dates_li only for the preparation of example data.
>
> So let's suppose I have the array "dates_array" returned from a
> a function.
Just use dates_array instead of dates_li, then.
>
> hours_array = dates_array.copy()
> for i in range(0, dates_array.size):
> hours_array[i] = dates_array[i].hour
>
* What's the point of making a copy of dates_array ? dates_array is a
ndarray of object, right ? And you want to take the hours, so you
should have an ndarray of integers for hours_array.
* The issue I have with this part is that you have several calls to
__getitem__ at each iteration. It might be faster to use create
hours_array as a block:
hours_array=np.array([_.hour for _ in dates_array], dtype=np.int)
More information about the Numpy-discussion
mailing list