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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:03:16+00:00 2026-05-26T12:03:16+00:00

i want to create a program which calculates the average of N random numbers

  • 0

i want to create a program which calculates the average of N random numbers taken from a uniform random number distribution.The program must run for
Ν=10,100,1000,10000,100000,1000000 random numbers.Then,i have to plot the mean value as
a function of N.

I did this:

from scitools.std import *
import matplotlib.pyplot as plt


N=10

distribution=[]
for i in range(1,7):   
    N*=10
    random_numbers=[random.uniform(0,1,size=N)]   
    distribution.append(random_numbers)


plt.semilogx(array(range(N)),array(distribution).mean())
plt.xlabel('N')
plt.grid(True)
plt.show()

It gives me the error in the title in the line where i do the plot.
Also,if there is another ,more pythonic way of doing this i’ll appreciate it.

Thank you.

  • 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-26T12:03:17+00:00Added an answer on May 26, 2026 at 12:03 pm
    import scipy
    import matplotlib.pyplot as plt
    
    Ns=[10**i for i in range(1,7)]
    means=[scipy.random.uniform(0,1,size=N).mean() for N in Ns]
    
    plt.semilogx(Ns,means)
    plt.xlabel('N')
    plt.grid(True)
    plt.show()
    
    1. As has already been mentioned, distribution is a list of arrays,
      with the inner arrays having different shapes. You can’t form a numpy
      array out of such an object by calling np.array(distribution).
    2. At least for plotting purposes, you don’t need to save the entire
      distribution. Just compute and store the means. A succinct way to do
      that is to use a list comprehension.
    3. Don’t use from module import * in scripts. It makes it hard
      to trace where variables come from. The from module import * was
      made (mainly) for use in interactive sessions, but generally not recommended for scripts.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a program which calculates how long it will take to
I want to create a program which opens my file onClick by providing its
I want to create a program that requests from the user 10 grades and
I want to create a program which can limit cpu usage of a process
I just want to create a program which crops an image and sends the
I want to create a python program which splits up a files into segments
I want to create a program, which can encrypt and decrypt a complete file
I am generating a random number of 32 bytes (which from Microchip PIC24F). When
I want to create an auto-complete program in java which should provide a list
I created one GWT webapplication project.Inthat i want to create servlet program,but in that

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.