np.random.random()和 np.random.random_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)的二维随机数数组。

如果大家觉得有用,请高抬贵手给一个赞让我上推荐让更多的人看到吧~

猜你喜欢

转载自blog.csdn.net/u011699626/article/details/109032528