[Python] Generating random numbers using numpy lib

复制代码
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()    
复制代码

 

posted @   Zhentiw  阅读(279)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2016-12-17 [Angular Router] Lazy loading Module with Auxiliary router
2016-12-17 [Now] Configure secrets and environment variables with Zeit’s Now
2015-12-17 [Javascript] Advanced Reduce: Flatten, Flatmap and ReduceRight
2015-12-17 [Redux] Composition with Objects
2014-12-17 [Javascript] Function scope
2014-12-17 [AngularJS] ui-router: named views
2014-12-17 [AngularJS] ui-router: Abstract States
点击右上角即可分享
微信分享提示