randomisation_matrix()函数生成随机矩阵 使用Python的线性代数

本文介绍了如何利用numpy.random.random()函数创建介于0和1之间的随机值矩阵。randomisation_matrix()函数接受行数和列数作为输入,返回相应大小的随机值矩阵,该矩阵在机器学习、神经网络、概率统计和马尔可夫矩阵等领域有应用。
摘要由CSDN通过智能技术生成

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:

应用范围:

  1. Machine Learning

    机器学习

  2. Neural Network

    神经网络

  3. Probability - (PMF specifically)

    概率-(专门针对PMF)

  4. Statistics and Inference

    统计与推断

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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值