1) Copy the example program python_example_a.py from my web page into your own linux area, then run it. There's nothing to hand in for this part: I'll take your word for your success or otherwise. 2) Cut the example program in two pieces. The first part should contain just the 'reaction_to_food' function and will be a stand-alone module. The second part, which should contain the remains of the example program, should import this module. (Hint: try the 'from import *' syntax to avoid making lots of changes to part 2.) If you now run part 2 alone you should get the same result as running the original program. There's nothing to hand in for this part: I'll take your word for your success or otherwise. Remember you will probably have to do 'export PYTHONPATH=' in order for python to find the module. 3) Write a short program which imports the numpy module. Then - Use the 'array()' function of numpy to construct a 2-dimensional array object 'myarray' which has the following values: 1 5 0 0 7 -1 4 -4 4 -3 2 -1 - Print the shape attribute of myarray - confirm it is (4,3) (ie 4 rows, 3 columns). - Print the value of the element in the 1st column, 3rd row of myarray (remember python starts counting from 0!). - Use the 'zeros()' function of numpy to construct a 1-dimensional array object 'myvec' of length 3 (filled with zeros, obviously). - Set the first element of myvec to 3. - Multiply myarray and myvec using the 'dot()' function of numpy. Print the result (should equal [3,0,12,-9]). 4) For the next python exercise you need to obtain 100 random numbers which have the gaussian or 'normal' probability distribution, with a standard deviation (often just called 'sigma') of 2.5. You can generate these random numbers in one of several ways. You should find at least 3 available modules which let you do this: scipy, numpy and RandomArray (the last is actually part of the Numeric package). The respective calls are as follows: scipy.stats.norm.rvs(size=100,scale=2.5) numpy.random.normal(size=100, scale=2.5) RandomArray.normal(0.0, 2.5, shape=(100)) - Write a python program which generates these random numbers. - Calculate the average, the uncertainty in the average, and the standard deviation of this set of numbers. Verify that the average is close to zero (what does 'close to' in this context mean?) and that the standard deviation is close to 2.5. 5) Suppose we have a long list of random numbers. It is nice to be able to look at their frequency distribution - that is, how many of them fall between x and x+delta_x, etc. Tallying up how many values fall within 'bins' of width delta_x is called making a frequency histogram. - Write a python module which contains a function which makes a histogram. (There are modules available which will calculate a histogram for you, but I want you to invent your own - it is a good exercise.) Obviously, among the arguments to the function, you will want to include the list of random numbers. You might also want to include other arguments to set how wide the bins are, where the first bin starts, the total number of bins, etc. There are several ways to do this, none of them perfect. Have a think about it. - Write a program which - imports your histogram module, - generates a list of 100,000 normally-distributed random numbers of sigma = 1.0, - makes a histogram of these values (using about 100 bins), - plots the histogram (using ppgplot, pgplot_aux, or pylab), - and draws on the same plot the ideal Gaussian curve of the same sigma value.