NumPy random.uniform() function in Python is used to create arrays filled with random samples which are from a uniform distribution. Uniform distribution is a probability-related distribution. This function returns the samples that are uniformly distributed over the given intervals of low and high. In uniform samples result, it includes low but excludes high. Show
In this article, I will explain np.random.uniform() function syntax and using its parameters how to get uniform distribution of random samples of the single and multi-dimensional arrays with examples. To create an array of uniform random values, pass 1. Quick Examples of Python NumPy random.uniform() FunctionFollowing are quick examples of random.uniform() Function. For more examples of NumPy array refer to NumPy Tutorial.
2. Syntax of NumPy random.uniform()Following is the syntax of random.uniform().
2.1 Parameters of random.uniform()Following are the Parameters of random.uniform()
2.2 Return Value of random.uniform()It returns an array of random samples that are taken from the uniform distribution over the given intervals. If the size is not provided, it will return a single random sample. 3. Usage of random.uniform()Numpy is a package for working with numeric data in Python. As we know NumPy has many functions that are used mostly for creating an arrays and some of them are used for manipulating the data in an array. 3 function is the built-in function, it generates random samples from a uniform distribution and creates a NumPy array with these values.If we do not provide any parameter to this function it will return a single random sample of uniform distribution. We will get a different random sample when we run the same code multiple times.
4. Get the Uniform Random Samples of 1-D ArrayWhen we pass the 4 as a value to the size parameter to this function, it will return the array of the random samples with the length specified with size . Let’s take an example,
5. Get the Random Samples of Given IntervalSpecify the
6. Get the Random Samples of Multi-Dimensional ArrayWhen we pass the tuple of int as a parameter into this function along with specified intervals, it can return a multi-dimensional NumPy array of random samples which are formed from the uniform distribution. The shape of the NumPy array would be equal to the value of the size param. Let’s take an example,
7. Graphical Presentation of random.uniform()To make a histogram with the help of the 1 library and print the graph of the NumPy random uniform distribution.
ConclusionIn this article, I have explained NumPy 3 and using this how to get the random values of 1-D NumPy array and multidimensional array, where the elements are from a uniform distribution between low and high value. |