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)
的二维随机数数组。
上一篇: vue中的ref和$refs的使用
下一篇: Redis协议,简单实现Jedis客户端