Random sampling in numpy | random() function Read Courses Practice Improve Improve Improve Like Article Like Save Article Save Report issue Report numpy.random.random() 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.random(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 : # Python program explaining # numpy.random.random() function # importing numpy import numpy as geek # output array out_arr = geek.random.random(size = 3) print ("Output 1D Array filled with random floats : ", out_arr) Output : Output 1D Array filled with random floats : [ 0.21698734 0.01617363 0.70382199] Code #2 : # Python program explaining # numpy.random.random() function # importing numpy import numpy as geek # output array out_arr = geek.random.random(size =(2, 4)) print ("Output 2D Array filled with random floats : ", out_arr) Output : Output 2D Array filled with random floats : [[ 0.95423066 0.35595927 0.76048569 0.90163066] [ 0.41903408 0.85596254 0.21666156 0.05734769]] Code #3 : # Python program explaining # numpy.random.random() function # importing numpy import numpy as geek # output array out_arr = geek.random.random((2, 3, 2)) print ("Output 3D Array filled with random floats : ", out_arr) Output : Output 3D Array filled with random floats : [[[ 0.07861816 0.79132387] [ 0.9112629 0.98162851] [ 0.0727613 0.03480279]] [[ 0.11267727 0.07631742] [ 0.47554553 0.83625053] [ 0.67781339 0.37856642]]] Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills and become a part of the hottest trend in the 21st century. Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve. Last Updated : 26 Feb, 2019 Like Article Save Article Previous Random sampling in numpy | ranf() function Next Random sampling in numpy | random_sample() function Share your thoughts in the comments Add Your Comment Please Login to comment...