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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:13:46+00:00 2026-06-08T19:13:46+00:00

I am using this loop in my python code: final_fun=[] for i_base in xrange(n_base):

  • 0

I am using this loop in my python code:

final_fun=[]
for i_base in xrange(n_base):
  final_fun.append(sum(fun[:,i_base])/n_ci)

and I would want to know how I can simplify this loop? If I simplify this loop will my program be faster? In general I know how to simplify this but here I am blocked by the append!

  • 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-08T19:13:48+00:00Added an answer on June 8, 2026 at 7:13 pm

    Use list comprehensions. It’s faster and cleaner. The interpreter can be slowed down a lot by the for loop, and there’s nothing to lose by simply rearranging the syntax.

    See this explanation for more details.

    final_fun = [sum(fun[:,i_base])/n_ci for i_base in xrange(n_base)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this code in a loop to populate an NSMutable Array of
Pylint says W: 6: Using possibly undefined loop variable 'n' ... with this code:
I'm using Python 2.6.6 I have this code: height = 20 width = 10
I'm using python 2.6.6 and I can't solve my problem. I have this code:
Since now, I'm using this loop to iterate over the elements of an array,
Using PHP I echo out table rows in a loop like this: <?php /*
I need to write this program using a loop https://i.stack.imgur.com/gko6T.jpg this is what i
I am using a foreach loop within PHP similar to this: foreach ($class->getAttributes() as
How do I simplify this templated vector initializer loop using lambdas or some kind
Detailed scenario is like this : I am creating 10 buttons using a loop

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.