欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

np.random.random()和 np.random.random_sample()是一致的

程序员文章站 2022-05-19 14:14:19
从官方文档上来看。我并没有发现np.random.random()与np.random.random_sample()在用法上有什么不同之处,所以它们两个在本质上都是一样的,随机给出设定的size尺寸的位于[0,1)半开半闭区间上的随机数。代码如下:# -*- coding: utf-8 -*-"""np.random.random()"""import numpy as npclass Debug: def __init__(self): self.sample...

从官方文档上来看。我并没有发现np.random.random()np.random.random_sample()在用法上有什么不同之处,所以它们两个在本质上都是一样的,随机给出设定的size尺寸的位于[0,1)半开半闭区间上的随机数。
代码如下:

# -*- coding: utf-8 -*- """
np.random.random()
""" import numpy as np class Debug: def __init__(self): self.sample = None self.sample1 = [] def mainProgram(self): np.random.seed(2) self.sample = np.random.random_sample(size=(2, 2)) self.sample1 = np.random.random((2, 2)) print("The value of sample is: ") print(self.sample) print("The value of sample1 is: ") print(self.sample1) if __name__ == '__main__': main = Debug() main.mainProgram() """
The value of sample is: 
[[0.4359949  0.02592623]
 [0.54966248 0.43532239]]
The value of sample1 is: 
[[0.4203678  0.33033482]
 [0.20464863 0.61927097]]
""" 

此处均给出了尺寸为(2,2)的二维随机数数组。