Python Numpy random randint()














































Python Numpy random randint()



Description
NumPy generally stands for Numerical Python and it is a general purpose array processing package.it always provides a high performance multidimensional array object. Numpy is usually for creating an array of n dimensions.

Method Name :numpy.random.randint(low, high=None, size=None, dtype=’l’)
Description : The function for doing random sampling in NumPy and the method in Python returns a random integer value between the two lower and higher limits (including both limits) i.e. in the interval [low, high) provided as two parameters. It should be noted that this method is only capable of generating integer-type random values.

The lower limit is the starting point from and including which the random integer would be generated, The upper limit is the stopping point up to which the method would return the random integer.

In this article, I will tell you about the parameter and its description
Parameter Name: low
Description :int
The lowest integer is to be drawn from the distribution. But, it works as the highest integer in the sample if high=None.

Parameter Name: high
Description :int
Largest integer to be drawn from the distribution.

Parameter Name: size
Description : int or tuple of ints
If the given shape is, e.g., (m, n, k), then m * n * k samples are drawn. Default is None, in which case a single value is returned.

Parameter Name: d-type
Description : Desired required output

Return : Array of random integers in the interval [low, high) or a single such random int if size not provided.

The first step would be to give syntax
command:
numpy.random.randint(low, high=None, size=None, dtype=’l’)

Example :
Code :
import random beg=20 end=200 random_integer = random.randint(beg, end) print("The random integer is :", random_integer)

Output :
Example :
Code :
# numpy.random.randint() function # importing numpy import numpy as np # output array out_arr = np.random.randint(low = 5, size =(4,5)) print ("Output 2D Array filled with random integers : ", out_arr)

Output :
Example :
Code :
# numpy.random.randint() function # importing numpy import numpy as np # output array out_arr = np.random.randint(4, 20, (5,6,7)) print ("Output 2D Array filled with random integers : ", out_arr)

Output :


Comments