Articles → Numpy → Rand Function In Numpy
Rand Function In Numpy
Purpose
Syntax
random.rand([number1, number 2….])
- Input parameter is optional.
- If no input parameter is passed, then the function will return a single number between 0 and 1.
- 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.
- 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.
- 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
Click to Enlarge