numpy 随机

    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))
    # todo [0,10)-->抽五个,放回抽样 [1 7 0 7 1 2 3],replace=False不放回抽样
    unique2=np.random.choice(10,7,replace=True)
    print("range(0,3)--->放回抽样:",unique,sep="\n")
    print("============")
    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)]))

  

猜你喜欢

转载自www.cnblogs.com/SunshineKimi/p/12458099.html
今日推荐