Home »
Python »
Linear Algebra using Python
randomisation() Function to generate Random Vector | Linear Algebra using Python
Linear Algebra using Python | randomisation_matrix() Function to generate Random Matrix: Here, we are going to learn about the randomisation_matrix() Function in Python?
Submitted by Anuj Singh, on May 22, 2020
Prerequisite: numpy.random.random( ) function with no input parameter
Numpy is the library of function that helps to construct or manipulate matrices and vectors. The function numpy.random.random() is a function used for generating a random value between 0 and 1. Now we are going to use this function to create a vector of elements having random value between 0 and 1. In this article, we are defining a function called randomisation() which returns a vector.
Syntax:
random_vector = randomisation(length_n)
Input parameter(s):
- length_n – represent the length of the vector.
Return value:
It returns a vector of length length_n with random values (between 0 and 1) at each entry.
Applications:
- Machine Learning
- Neural Network
- Probability - (PMF specifically)
- Statistics and Inference
Python code to demonstrate example of randomisation() function
# Linear Algebra Learning Sequence
# Randomisation Function which return a vector
import numpy as np
def randomization(n):
x = np.random.random([n,1])
return x
n = int(input('Length of vector: '))
print(randomization(n))
Output:
RUN 1:
Length of vector: 4
[[0.05183679]
[0.31612445]
[0.09396175]
[0.5120439 ]]
RUN 2:
Length of vector: 15
[[0.82281558]
[0.69170917]
[0.97428563]
[0.95208111]
[0.67069261]
[0.1387415 ]
[0.42731091]
[0.5170017 ]
[0.4783402 ]
[0.14740506]
[0.59898893]
[0.17684872]
[0.53167923]
[0.4925715 ]
[0.59492722]]