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 7579347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:39:21+00:00 2026-05-30T17:39:21+00:00

In python I have numpy.ndarray called a and a list of indices called b

  • 0

In python I have numpy.ndarray called a and a list of indices called b. I want to get a list of all the values of a which are not in -10..10 places around the indices of b.
This is my current code, which takes a lot of time to run due to allocations of data (a is very big):

    aa=a
    # Remove all ranges backwards
    for bb in b[::-1]:
        aa=np.delete(aa, range(bb-10,bb+10))

Is there a way to do it more efficiently? Preferably with few memory allocations.

  • 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-30T17:39:22+00:00Added an answer on May 30, 2026 at 5:39 pm

    np.delete will take an array of indicies of any size. You can simply populate your entire array of indicies and perform the delete once, therefore only deallocating and reallocating once. (not tested. possible typos.)

    bb = np.empty((b.size, 21), dtype=int)
    for i,v in enumerate(b):
        bb[i] = v+np.arange(-10,11)
    
    np.delete(a, bb.flat)  # looks like .flat is optional
    

    Note, if your ranges overlap, you’ll get a difference between this and your algorithm: where yours will remove more items than those originally 10 indices away.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object of type 'numpy.ndarray', called myarray, that when printed to the
I have 1-dimensional numpy array ( array_ ) and a Python list (list_). The
Does Python have a pool of all strings and are they (strings) singletons there?
I have Python 2.6 and I want to install easy _ install module. The
I have a Python program that processes fairly large NumPy arrays (in the hundreds
I have a 2D numpy array of shape (N,2) which is holding N points
I'm working in an embedded Linux environment and I have some Python code which
Let's suppose I have a numpy matrix variable called MATRIX with 3 coordinates: (x,
I have a python web server (cherrypy), and I want the user to be
I have a numpy array of dimension (48, 366, 3) and I want to

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.