randomisation_matrix() Function to generate Random Matrix | 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 matrix of elements having a random value between 0 and 1. In this article, we are defining a function called randomisation_matrix() which returns a vector.

Syntax:

    random_mat = randomisation_matrix(rows, columns)

Input parameter(s):

  • rows, columns – represent the number of rows and columns.

Return value:

A Matrix of dimension (rows x columns) with random values (between 0 and 1) at each entry

Applications:

  1. Machine Learning
  2. Neural Network
  3. Probability - (PMF specifically)
  4. Statistics and Inference
  5. Markov Matrix

Python code to demonstrate example of randomisation_matrix() function

# Linear Algebra Learning Sequence
# randomisation_matrix() Function 
# to generate Random Matrix

import numpy as np

# defining a function in input arguements 
# as row and column numbers
def randomization_matrix(m,n):
   x = np.random.random([m,n])
   return x

m = int(input('Number of Rows: '))
n = int(input('Number of Columns: '))

# printing the random matrix
print(randomization_matrix(m,n))

Output:

RUN 1:
Number of Rows: 3
Number of Columns: 3
[[0.78101157 0.78051788 0.36688224]
 [0.61297243 0.95915371 0.10535508]
 [0.80270319 0.78350465 0.01176104]]

RUN 2:
Number of Rows: 9
Number of Columns: 4
[[0.35716108 0.33297787 0.66591572 0.54160728]
 [0.53952926 0.84150531 0.49277988 0.21231327]
 [0.63708892 0.12742805 0.80148422 0.78332466]
 [0.47448847 0.27764141 0.81580429 0.15018078]
 [0.65042576 0.51910242 0.42151608 0.5270826 ]
 [0.72498296 0.95011068 0.0472314  0.19193858]
 [0.18470833 0.90463529 0.44257893 0.46191247]
 [0.40482905 0.95049498 0.61134395 0.80097087]
 [0.50008522 0.99844731 0.90253853 0.42075036]]






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.