Articles → Numpy → Rand Function In Numpy

Rand Function In Numpy






Purpose





Syntax


random.rand([number1, number 2….])




  1. Input parameter is optional.
  2. If no input parameter is passed, then the function will return a single number between 0 and 1.
  3. If 1 parameter is passed, then the function will return a single-dimensional array (all the values are between 0 and 1). The number of items in an array is equal to the value passed as a parameter.
  4. If 2 parameters are passed, then the function will return a two-dimensional array (all the values are between 0 and 1), and so on.
  5. The output will be a floating-point number.

Example


import numpy as np

print("No value is passed - ",np.random.rand())
print("One value is passed - ",np.random.rand(2))
print("Two values are passed - ",np.random.rand(2,2))



Output


Picture showing the output of the rand function in python
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Monday, March 25, 2019

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250