Python Numpy random random_sample()














































Python Numpy random random_sample()



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.random_sample(size=None)
Description :Also represented as random.sample(sequence, k)
The function is for solving random sampling in NumPy. It will always return an array of specified shape and fill it with random floats in the half-open interval [0.0, 1.0).

In this article, I will tell you about the parameter and its description
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: sequence
Description : A sequence can be any type of sequence like as: list, set, range, etc.

Parameter Name: k
Description :The size of the returned list.

Return :The array of random floats in the interval [0.0, 1.0) or a single such random float if size not provided in the given output.

The first step would be to give syntax
command:
numpy.random.random_sample(size=None)

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

Output :
Example :
Code :
# numpy.random.random_sample() function # importing numpy import numpy as np # output array out_arr = np.random.random_sample((5,7,6)) print ("Output 3D Array filled with random floats : ", out_arr)

Output :


Comments