Prerequisite: numpy.random.random( ) function with no input parameter
先决条件: numpy.random.random()函数,无输入参数
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.
Numpy是一个功能库,可帮助构造或操纵矩阵和向量。 函数numpy.random.random()是用于生成介于0和1之间的随机值的函数。现在,我们将使用该函数来创建具有介于0和1之间的随机值的元素的矩阵。我们正在定义一个称为randomisation_matrix()的函数,该函数返回一个向量。
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
每个条目的维度矩阵(行x列)具有随机值(0到1之间)
Applications:
应用范围:
Machine Learning
机器学习
Neural Network
神经网络
Probability - (PMF specifically)
概率-(专门针对PMF)
Statistics and Inference
统计与推断
Markov Matrix
马尔可夫矩阵
Python代码演示randomisation_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]]
翻译自: https://www.includehelp.com/python/randomisation_matrix-function-to-generate-random-matrix.aspx