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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:57:32+00:00 2026-06-09T02:57:32+00:00

In my program I need to work with arrays roughly 500×500 to 1500×1500 within

  • 0

In my program I need to work with arrays roughly 500×500 to 1500×1500 within a function that is looped over 1000’s of times. In each iteration, I need to start with an array that has the same form (whose dimensions are fixed across all iterations). The initial values will be:

[0 0 0 ... 1]
[0 0 0 ... 1]
....

However, the contents of the array will be modified within the loop. What is the most efficient way to “reset” the array to this format so I can pass the same array to the function every time without having to allocate a new set of memory every time? (I know the range of rows that were modified)

I have tried:

a[first_row_modified:last_row_modified,:] = 0.
a[first_row_modified:last_row_modified,:-1] = 1.

but it takes roughly the same amount of time as just creating a new array every time with the following:

a = zeros((sizeArray, sizeArray))
a[:,-1] = 1.

Is there a faster way to effectively “erase” the array and change the last column to ones? I think this is similar to this question, clearing elements of numpy array , although my array doesn’t change sizes and i didn’t see the definitive answer to the previously asked question.

  • 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-09T02:57:34+00:00Added an answer on June 9, 2026 at 2:57 am

    No; I think the way you are doing it is about as fast as it gets.

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

Sidebar

Related Questions

I need to write a simple program for work that does the following: read
Throughout my iOS program. I create multiple arrays that all work together to make
Program for work with arrays in dynamic memory. Need equivalent for C. Can anybody
I need to work with decimals. In my program, the user need to put
I need a program that checks if the difference between all pairs of elements
I need to create a program that takes 'N' as Input and show the
I have roughly 420,000 elements that I need to store easily in a Set
Hello for my program I must validate input for multiple arrays in another function.
I need to create a C++ dll that will be called from another program
I know downcasting like this won't work. I need a method that WILL work.

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.