码迷,mamicode.com
首页 > 编程语言 > 详细

[Python] Generating random numbers using numpy lib

时间:2017-12-18 01:29:54      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:data   4.4   dom   pytho   1.5   div   class   5.5   gpo   

import numpy as np 

def test_run():
    data=np.random.random((3,4))
    """
    [[ 0.80150549  0.96756513  0.18914514  0.85937016]
    [ 0.23563908  0.75685996  0.46804508  0.91735016]
    [ 0.70541929  0.04969046  0.75052217  0.2801136 ]]
    """

    data=np.random.rand(3,4)
    """
    [[ 0.48137826  0.82544788  0.24014543  0.56807129]
    [ 0.02557921  0.50690438  0.29423376  0.85673923]
    [ 0.32648763  0.97304461  0.6034564   0.70554691]]
    """

    data=np.random.normal(size=(2,3)) #mean=0, sd=1
    """
    [[ 1.57598046  0.06976049 -1.6502364 ]
    [ 0.30437287 -0.88249543 -0.04233034]]
    """
    data=np.random.normal(50,10,size=(2,3)) #mean=50, sd=10
    """
    [[ 34.40308274  56.17179863  36.05758636]
    [ 57.38723594  41.43156664  65.54296858]]
    """
    print(np.random.randint(10)) #6
    print(np.random.randint(0,10)) #9
    print(np.random.randint(0,10,size=(5))) #[2 1 8 4 1]
    print(np.random.randint(0,10,size=(2,3))) 
    """
    [[0 2 4]
    [3 8 3]]
    """

if __name__ == "__main__":
    test_run()    

 

[Python] Generating random numbers using numpy lib

标签:data   4.4   dom   pytho   1.5   div   class   5.5   gpo   

原文地址:http://www.cnblogs.com/Answer1215/p/8053885.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!