[Numpy-discussion] Accessing fields of the object stored in numpy array

Vishal Rana ranavishal@gmail....
Thu Feb 18 00:12:00 CST 2010


Hi,

I have a numpy arrays with datetime objects as:

a = np.array([dt.datetime(2010, 2, 17), dt.datetime(2010, 2, 16),
dt.datetime(2010, 2, 15)])
b = np.array([dt.datetime(2010, 2, 14), dt.datetime(2010, 2, 13),
dt.datetime(2010, 2, 12)])

I want doing a-b should give me days difference as numpy array but I get as:
array([3 days, 0:00:00, 3 days, 0:00:00, 3 days, 0:00:00], dtype=object)
which is a numpy array of timedelta! I can extract days out by using
property days of each, but how I do it in a numpy way may like:
c=a-b
c.days (a numpy array of days difference) like:
array([3, 3, 3])

Any pointers?

Thanks
Vishal Rana
Joan Crawford<http://www.brainyquote.com/quotes/authors/j/joan_crawford.html>
- "I, Joan Crawford, I believe in the dollar. Everything I earn, I
spend."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100217/66b39797/attachment.html 


More information about the NumPy-Discussion mailing list