Previously, we discussed how to generate discrete random variables like binomial or Poisson. Now let us generate some continuous random variables like uniform. Again, we can use special functions from numpy.random or scipy.stats to do it. For example, let us begin with numpy.random and import uniform. Uniform is a random number generator that uses a uniform distribution on a sub-segment. Again, we can check how it works. We can define end points of the segment. For example, I want to generate some random numbers with uniform distribution on segment from negative 2 to plus 2. So I have to specify low and high limits. Now you see that the numbers that we have are just some real numbers in this interval. As usual, we can specify size argument to generate samples from this random variable, and to visualize the results of this generation, we can use histograms. Let me show you how histograms work in Python. We have to use a matplotlib.pyplot. Again, some magic columns here. To study how histograms work, let us consider some artificial data set. For example, I have some data 1, 1.2, 4.1, 4.2, 4.3, 5, and I can use hist to visualize this data set. Let me use different number of bins to make the picture more explicit. You see here are two rectangles. First rectangle is over this segment and it heights corresponds to the number of points that lie inside this segment. Let us draw this points as well. I can use plt.plot to do it. So x-coordinates of our points will be these numbers that is in list data, and I will put some fixed y-coordinate. For example, 0.1 times len of data. So every point will have the same y-coordinate, and let us add some markers here. So you see that over this segment, we have two points, and over this segment, we have four points. So this rectangle have height two and this rectangle have height four. We can also add option density equals to true. After this option, we re-scale to the vertical axis in such a way that the area of this picture equals to one. So this picture resembles the probability density function. Now we can see how this picture will change when we change our data set. For example, let us move this point here. I have to replace 1.2 into 3 and start this comment again. You see that now we have two rectangles of the same height here and here, and this rectangle is higher proportionally to the number of points. Now we can use this histogram to study on the samples that was gathered from this uniform function. Now we see that this histogram does not resemble the probability density function as expected. But this is due to low size of our sample. Let us increase sample size a little bit. This is much better. Let us increase it more and more. Let us add density equals to true here. Now from this histogram, we see that the probability of getting our random variable on every segment is more or less the same provided that the length of these segments is the same. We see that the heights of corresponding rectangles are more or less equal at least approximately. Now let us draw on the same graph the corresponding probability density function. To get this function we can use corresponding object from scipy.stats package. I will do it in the following way. I will import scipy.stats, and now I will use scipy.stats uniform to avoid collision with this function uniform which is from numpy library. So to create the corresponding object, we have to specify the parameters of the distribution. In contrast with this function uniform, when we specify left and right endpoints of a segment, here we specify left end point of a segment and length of the segment. Now we can use this object to find, for example, probability density function at arbitrary point. For example, at point 1.2, the value of probability density function is one quarter which is correct because the length of our segment is four. Now let us draw the graph of this function. To do so, we import numpy. Again, to plot a graph of a function, we have to specify a set of points at which the corresponding values of function will be found. These points will be shown on the graph. It is easy to use numpy linspace function to create the corresponding set of x values. Let us assume that we start from negative 3 and end at 3, and we need 100 points. Now x is just in this list of values from negative 3 to 3. Then I will plot x, X.PDF of x small, and this is actually the graph that we discussed at the lectures, and we can draw this graph on the same picture as this histogram. So let me just copy paste it here. Now we see that our histogram actually approximates the corresponding probability density function. The larger sample size, the better approximation is. We can use a similar technique to analyze any probability distribution. For example, one of the most important distribution for us is normal distribution. Of course, Python can generate normally distributed random variables as well. We will discuss it later.