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 vector of elements having random value between 0 and 1. In this article, we are defining a function called randomisation() which returns a vector.
Numpy是一个功能库,可帮助构造或操纵矩阵和向量。 函数numpy.random.random()是用于生成介于0和1之间的随机值的函数。现在,我们将使用该函数来创建具有介于0和1之间的随机值的元素的向量 。正在定义一个称为randomization()的函数,该函数返回一个向量。
Syntax:
句法:
random_vector = randomisation(length_n)
Input parameter(s):
输入参数:
length_n – represent the length of the vector.
length_n –表示向量的长度。
Return value:
返回值:
It returns a vector of length length_n with random values (between 0 and 1) at each entry.
它在每个条目处返回一个长度为length_n的向量,该向量具有随机值(0到1之间)。
Applications:
应用范围:
Machine Learning
机器学习
Neural Network
神经网络
Probability - (PMF specifically)
概率-(专门针对PMF)
Statistics and Inference
统计与推断
Python代码演示randomization()函数的示例 (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]]
翻译自: https://www.includehelp.com/python/randomisation-function-to-generate-random-vector.aspx