Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8442643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:53:49+00:00 2026-06-10T08:53:49+00:00

I have some input data, with timestamps in the input file in the form

  • 0

I have some input data, with timestamps in the input file in the form of hours from the date time specified in the filename.

This is a bit useless, so I need to convert it to python datetime.datetime objects, and then put it in a numpy array. I could write a for loop, but I’d like to do something like:

numpy.arange(datetime.datetime(2000, 1,1), datetime.datetime(2000, 1,2), datetime.timedelta(hours=1))

which throws a TypeError.

Can this be done? I’m stuck with python 2.6 and numpy 1.6.1.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:53:51+00:00Added an answer on June 10, 2026 at 8:53 am

    See NumPy Datetimes and Timedeltas. Since NumPy 1.7, you can represent datetimes in NumPy using the numpy.datetime64 type, which permits you to do ranges of values:

    >>> np.arange(np.datetime64("2000-01-01"), np.datetime64("2000-01-02"), np.timedelta64(1, "h"))
    array(['2000-01-01T00', '2000-01-01T01', '2000-01-01T02', '2000-01-01T03',
           '2000-01-01T04', '2000-01-01T05', '2000-01-01T06', '2000-01-01T07',
           '2000-01-01T08', '2000-01-01T09', '2000-01-01T10', '2000-01-01T11',
           '2000-01-01T12', '2000-01-01T13', '2000-01-01T14', '2000-01-01T15',
           '2000-01-01T16', '2000-01-01T17', '2000-01-01T18', '2000-01-01T19',
           '2000-01-01T20', '2000-01-01T21', '2000-01-01T22', '2000-01-01T23'],
          dtype='datetime64[h]')
    

    For NumPy 1.6, which has a much less useful datetime64 type, you can use a suitable list comprehension to build the datetimes (see also Creating a range of dates in Python):

    base = datetime.datetime(2000, 1, 1)
    arr = numpy.array([base + datetime.timedelta(hours=i) for i in xrange(24)])
    

    This produces

    array([2000-01-01 00:00:00, 2000-01-01 01:00:00, 2000-01-01 02:00:00,
       2000-01-01 03:00:00, 2000-01-01 04:00:00, 2000-01-01 05:00:00,
       2000-01-01 06:00:00, 2000-01-01 07:00:00, 2000-01-01 08:00:00,
       2000-01-01 09:00:00, 2000-01-01 10:00:00, 2000-01-01 11:00:00,
       2000-01-01 12:00:00, 2000-01-01 13:00:00, 2000-01-01 14:00:00,
       2000-01-01 15:00:00, 2000-01-01 16:00:00, 2000-01-01 17:00:00,
       2000-01-01 18:00:00, 2000-01-01 19:00:00, 2000-01-01 20:00:00,
       2000-01-01 21:00:00, 2000-01-01 22:00:00, 2000-01-01 23:00:00], dtype=object)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have next form and some ashx <form action=FileUpload.ashx method=POST enctype=multipart/form-data id=frmUpload> <input id=fileupload
I have some html like the following: <div class=control-group> <input type=text data-bind=value: $data.DealCode name=DealCode
I have some data (which users input using WYSIWYG editor). I have created a
I have some input like this: aaaaa bbb \n cccccc\n ddddd \neeee And I
i have one form which have some input box and some select box. i
I have a form with some input fields. I am using the tabStrip KendoUI
I have a form with some input fields and a little <div> to the
I have some code like below $(html).on(change, input['data-href'], function() { var href, obj, params;
I have some input values contained within a bunch of divs and a form.
I have some dirty input data that is being imported into a raw source

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.