numpy.random.ranf() is one of the function for doing random sampling in numpy. It returns an array of specified shape and fills it with random floats in the half-open interval
[0.0, 1.0).
Syntax : numpy.random.ranf(size=None)
Parameters :
size : [int or tuple of ints, optional] Output shape. 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.
Return : Array of random floats in the interval [0.0, 1.0). or a single such random float if size not provided.
Code #1 :
Output :
Output random float value : 0.0877051588430926
Code #2 :
Output :
Output 2D Array filled with random floats : [[ 0.14186407]
[ 0.58068259]]
Code #3 :