从度为30的t分布生成100 * 2阵列

时间:2016-11-15 19:19:40

标签: python numpy scipy

我正在为Python类的Python Scipy问题挣扎。我试图保持简单明了,所以我可以自己学习。

对此问题的任何帮助将不胜感激。感谢。

2 个答案:

答案 0 :(得分:2)

如果您特别想使用scipy执行此操作,则可以使用stats模块。这使您可以使用所选参数为分布创建对象,然后可以从中生成从该分布中提取的随机变量。因此,对于dof = 30的学生来说,你可以这样做:

from scipy.stats import t

my_t = t(30)

my_arr = my_t.rvs((100, 2))

答案 1 :(得分:1)

np.random.standard_t(30, (100, 2))
array([[ 0.2900961 , -0.49184654],
       [-0.66369036,  0.29856974],
       [-0.81205354, -0.73274099],
       [ 0.03983057, -1.63843224],
       [-1.48501012,  0.37018367],
       [-0.02788238, -2.73851282],
       [ 0.02121366, -0.29790155],
       [-0.06538505, -0.30493695],
       [ 1.35973227, -1.12887598],
       [ 0.02135389,  1.27192716],
       [ 0.45889757,  0.83632908],
       [ 0.11450415, -1.23755654],
       [ 0.75822006, -0.10754588],
       [ 1.17461175, -1.08492382],
       [ 1.53760935, -0.55211614],
       [ 1.7442242 , -0.51923315],
       [ 0.92816422, -1.93624871],
       [ 0.75735932,  0.31273475],
       [-0.71536809,  0.04971693],
       [-0.4094555 ,  0.85412734],
       [ 1.23209227, -1.01814822],
       [-0.83653207,  0.5476101 ],
       [-0.93710566, -0.68810908],
       [-0.33276732,  2.3529951 ],
       [ 1.78781951, -0.30588975],
       [ 0.38020327, -0.68367237],
       [ 0.32864593,  1.26141535],
       [-1.21311796, -1.25318568],
       [-0.82619795, -0.49099708],
       [-0.00987192,  1.24385043],
       [ 0.50069202, -0.67335928],
       [-1.10908519,  1.48047345],
       [ 0.84272651,  0.88305515],
       [ 1.03803068, -0.78190559],
       [-2.18620032,  1.35880684],
       [ 0.59731946, -0.10586537],
       [-0.06889232, -1.93968476],
       [ 0.91114411,  0.16464482],
       [ 1.63996227, -0.44997124],
       [ 0.63459803,  0.17235393],
       [ 0.14484818,  1.97338409],
       [ 0.19124964,  0.25048341],
       [ 1.05005178, -2.03222472],
       [ 0.39245172,  1.6927919 ],
       [-0.78692079,  1.00297447],
       [ 0.17231872,  1.87670916],
       [-0.5570899 , -1.12292151],
       [ 1.6123502 , -1.23264286],
       [-1.09187624, -1.12123467],
       [-1.25814082, -1.03345077],
       [-0.70254563,  0.52535811],
       [ 0.1981361 ,  0.98231126],
       [ 0.35442413,  2.22361201],
       [-1.15538729, -0.90178065],
       [ 0.58262176, -0.14912307],
       [-0.12245958, -0.7622139 ],
       [ 2.02454963, -1.23601746],
       [ 1.80337422, -1.26433357],
       [ 1.55435051, -0.30136764],
       [ 1.02185468, -1.01947832],
       [-0.97216339,  0.45184081],
       [ 0.70142966,  1.24516373],
       [-2.03826058, -0.22819802],
       [ 2.15868138, -0.75028286],
       [-0.13703708, -2.42009844],
       [ 0.11059006, -0.77753454],
       [ 0.60928961, -2.42947059],
       [-0.06756108, -0.24126194],
       [ 0.32133117,  0.5354973 ],
       [ 1.55587524,  0.02437769],
       [-0.08989499,  0.26808396],
       [ 0.32481833, -0.49148255],
       [ 1.37278471,  1.28359455],
       [ 1.11240391, -0.46442478],
       [-0.23700156,  3.52282209],
       [ 1.52313794,  0.32729436],
       [ 0.03314825,  0.48151337],
       [ 1.36774946, -1.36015715],
       [ 0.79938481,  1.88828935],
       [ 0.23314392, -2.19733862],
       [-1.76801664,  0.13285706],
       [ 0.72678452,  0.89537934],
       [ 0.69842504, -0.56114374],
       [ 1.01189122, -0.13459648],
       [-0.34997372, -0.5946139 ],
       [ 0.29432587,  1.47568117],
       [-1.39008419,  0.22297323],
       [-0.68324715, -0.12054717],
       [-0.44935036, -0.22928693],
       [-0.80951017,  1.48290706],
       [-0.34331734, -1.25514126],
       [-1.95957181, -0.2914293 ],
       [-0.74272681,  0.57470058],
       [-0.42099781, -0.25268629],
       [-2.26217783, -1.740979  ],
       [-0.25803757, -1.37507365],
       [-0.60466318, -0.81158367],
       [-0.0189305 , -0.27809122],
       [ 0.53366222, -1.01032679],
       [ 0.68300556,  0.27805818]])