randomisation()函数生成随机向量| 使用Python的线性代数

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:

应用范围:

  1. Machine Learning

    机器学习

  2. Neural Network

    神经网络

  3. Probability - (PMF specifically)

    概率-(专门针对PMF)

  4. 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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值