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

  • Home
  • SEARCH
  • 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 3340872
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:39:28+00:00 2026-05-18T00:39:28+00:00

I haven’t been able to find anything about this value error online and I

  • 0

I haven’t been able to find anything about this value error online and I am at a complete loss as to why my code is eliciting this response.

I have a large dictionary of around 50 keys. The value associated with each key is a 2D array of many elements of the form [datetime object, some other info]. A sample would look like this:

{'some_random_key': array([[datetime(2010, 10, 26, 11, 5, 28, 157404), 14.1],
                           [datetime(2010, 10, 26, 11, 5, 38, 613066), 17.2]],
                          dtype=object), 
'some_other_key':  array([[datetime(2010, 10, 26, 11, 5, 28, 157404), 'true'],
                          [datetime(2010, 10, 26, 11, 5, 38, 613066), 'false']], 
                         dtype=object)}

What I want my code to do is to allow a user to select a start and stop date and remove all of the array elements (for all of the keys) that are not within that range.

Placing print statements throughout the code I was able to deduce that it can find the dates that are out of range, but for some reason, the error occurs when it attempts to remove the element from the array.

Here is my code:

def selectDateRange(dictionary, start, stop):

    #Make a clone dictionary to delete values from 
    theClone = dict(dictionary)

    starting = datetime.strptime(start, '%d-%m-%Y')   #put in datetime format
    ending   = datetime.strptime(stop+' '+ '23:59', '%d-%m-%Y %H:%M')    #put in datetime format 

    #Get a list of all the keys in the dictionary
    listOfKeys = theClone.keys()

    #Go through each key in the list
    for key in listOfKeys:
        print key 

        #The value associate with each key is an array
        innerAry = theClone[key]

        #Loop through the array and . . .
        for j, value in enumerate(reversed(innerAry)):

            if (value[0] <= starting) or (value[0] >= ending):
            #. . . delete anything that is not in the specified dateRange

                del innerAry[j]

    return theClone

This is the error message that I get:

ValueError: cannot delete array elements

and it occurs at the line: del innerAry[j]

Please help – perhaps you have the eye to see the problem where I cannot.

Thanks!

  • 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-05-18T00:39:28+00:00Added an answer on May 18, 2026 at 12:39 am

    If you use numpy arrays, then use them as arrays and not as lists

    numpy does comparison elementwise for the entire array, which can then be used to select the relevant subarray. This also removes the need for the inner loop.

    >>> a = np.array([[datetime(2010, 10, 26, 11, 5, 28, 157404), 14.1],
                      [datetime(2010, 10, 26, 11, 5, 30, 613066), 17.2],
                      [datetime(2010, 10, 26, 11, 5, 31, 613066), 17.2],
                      [datetime(2010, 10, 26, 11, 5, 32, 613066), 17.2],
                      [datetime(2010, 10, 26, 11, 5, 33, 613066), 17.2],
                      [datetime(2010, 10, 26, 11, 5, 38, 613066), 17.2]],
                              dtype=object)
    >>> start = datetime(2010, 10, 26, 11, 5, 28, 157405)
    >>> end = datetime(2010, 10, 26, 11, 5, 33, 613066)
    
    >>> (a[:,0] > start)&(a[:,0] < end)
    array([False,  True,  True,  True, False, False], dtype=bool)
    >>> a[(a[:,0] > start)&(a[:,0] < end)]
    array([[2010-10-26 11:05:30.613066, 17.2],
           [2010-10-26 11:05:31.613066, 17.2],
           [2010-10-26 11:05:32.613066, 17.2]], dtype=object)
    

    just to make sure we still have datetimes in there:

    >>> b = a[(a[:,0] > start)&(a[:,0] < end)]
    >>> b[0,0]
    datetime.datetime(2010, 10, 26, 11, 5, 30, 613066)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I haven't been able to find any real documentation on this, so I'm wondering
I haven't been able to find any documentation on Android's sync services, so far
I haven't been able to find a solution for getting an Objective-C and XAuth
I haven't been able to find what these Xcode icons mean. Some you can
I haven't been able to solve this prolog exercise. I was hoping someone here
I haven't been able to find authorative explanations, microformats or guidelines for the following,
I haven't really been able to find any good simple tutorials an animating a
Haven't seen anything about it here but it seems to solve one of the
I haven't been able to get any more console output (to help with debugging)
I haven't found this question, feel free to close if it's already up here.

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.