numpy 随机种子

时间:2020-03-10 21:01:25   收藏:0   阅读:114
    from numpy import  random
    random.seed(1001)
    array=np.random.normal(0,1,(3,4))  # <class ‘numpy.ndarray‘>
    print(array)
    # [[-1.08644637 - 0.89606513 - 0.30629937 - 1.33993366]
    #  [-1.20658558 - 0.64172681  1.30794563  1.84546043]
    # [0.82911495 - 0.02329881 - 0.20856395 - 0.91661975]]

 随机种子,每次随机一样的数据出来

 from numpy  import random  

np.random.choice()

    from numpy import  random
    # todo random.seed(1001) ,是否每次使用一个种子数,设置对np.random.xx下文均有效
    unique= np.random.choice(range(0,3),(3,4))
    print("range(0,3)--->放回抽样:",unique,sep="\n")
    
    print("============")
    
    unique2 = np.random.choice(10, 7, replace=True)
    print("[0,10)-->抽五个,放回抽样",unique2)
    # # set columns of  dataframe : 1.df.columns=["x1","x1".....]
    print(pd.DataFrame(unique,columns=[f"x{i}"  for i in range(4)]))

  

技术分享图片

 

原文:https://www.cnblogs.com/SunshineKimi/p/12458099.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!