3.7. Exercises for Lecture 3#

3.7.1. Exercise 3.1#

  • Create a one-dimensional histogram filled with 5 values and save the histogram image to a png file

3.7.2. Exercise 3.2#

Read the text file eventi_unif.txt:

  • Print the first 10 positive elements to the screen.

  • Count the number of events contained in the file.

  • Determine the minimum and maximum values among the numbers saved in the file.

Instructions to download the file

To access the RAW version of the file, click on the Raw button at the top-right. To download it, one can use two methods:

  1. Open the link and use ‘Save as’ from your browser.

  2. Use the command wget <link> in the directory where the file has to be saved (e.g.: $ wget rawFileAddress)

3.7.3. Exercise 3.3#

Read the text file eventi_gauss.txt:

  • Fill a histogram with the first N numbers contained in the file, where N is a command-line parameter during program execution.

  • Choose the histogram’s definition range and its bin number based on the numbers to be represented.

3.7.4. Exercise 3.4#

  • Display the distributions of events from the two files of the previous exercises, overlaid, finding the best visualization for the comparison between the two histograms.

3.7.5. Exercise 3.5#

Read the text file eventi_unif.txt:

  • Calculate the mean of the numbers in the text file.

  • Calculate the variance of the numbers in the text file.

  • Calculate the standard deviation of the numbers in the text file.

  • Calculate the standard deviation from the mean of the numbers in the text file.

3.7.6. Exercise 3.6#

Write a python library which, given the name of a text file containing a sample of events as input, is able to read the sample and save it in a numpy array, then calculate its mean, variance, standard deviation, standard deviation from the mean, display the sample in a histogram with an appropriately chosen definition range and bin number. Write a test program for the created library.

3.7.7. Exercise 3.7#

Write a Python program to draw a Gaussian distribution and its cumulative function

3.7.8. Exercise 3.8#

Write a Python program to draw an exponential distribution and its cumulative function

3.7.9. Exercise 3.9#

Use the Python scipy.stat.norm object to determine the area of a normal distribution of its tails outside the range included within an interval of 1, 2, 3, 4, and 5 standard deviations around its mean

3.7.10. Exercise 3.10#

Write a Python program to draw a binomial distribution and its cumulative function

3.7.11. Exercise 3.11#

Write a Python program to draw a Poisson distribution for several values of its mean, overlapped

3.7.12. Exercise 3.12#

Write a Python program to draw a Poisson distribution. Show, by using the third and fourth central momenta calculations available in the scipy.stats library, that the momenta of a Poisson distribution asymptotically tend to the ones of a Gaussian.

3.7.13. Exercise 3.13#

What is the probability that ten measurements of the same quantity expected to be Gaussian fall within an interval of 1 standard deviation width around the mean?

3.7.14. Exercise 3.14#

What is the probability that ten measurements of the same counting experiment expected to be Poisson distributed are all larger than the expected average number of events?