Membuat data acak berdistribusi normal

Catatan sebelumnya tentang bagaimana membuat data secara acak dengan python, kali ini hampir sama. Bedanya, data yang dibuat berasal dari distribusi Gaussian (distribusi normal).

Akan dibuat data dengan besar sampel 200, mean 165, standar deviasi 12.5.

#!/usr/bin/python3
import numpy as np
sampel = 200
rerata = 165
deviasi = 12.5
data = np.random.normal(rerata, deviasi, sampel)
print(data)

Hasilnya

[169.9036172  158.13190825 156.9590178  167.74827264 168.62534857
 171.69140206 161.65434678 187.34374928 150.29836841 152.49471216
 160.69172875 173.22405024 171.53443046 159.89375268 170.59784794
 158.46572357 168.20110897 131.00882242 169.37660362 172.71471591
 162.34684852 159.31860527 156.87505418 152.25881337 173.94068172
 134.98130158 146.94872437 159.80322766 176.60094913 173.111627
 166.68329084 161.23836143 170.69908908 152.20927403 159.85371294
 160.92108223 174.01411013 145.55719871 179.99900982 180.02266499
 152.10976505 164.51292664 157.8864326  170.85776142 160.73666817
 174.51669873 149.72123539 164.06125902 165.84558021 170.64970455
 173.35880599 153.86472607 186.08708782 163.16383892 168.79688713
 161.76180346 159.76044878 152.08482654 170.20465648 175.60900504
 162.92716486 177.19471848 171.2871681  144.971927   164.3188071
 162.15660742 180.74130005 160.39323975 139.65007794 157.81802319
 156.85566358 166.50332995 177.2953798  158.30680384 177.13544237
 164.38845426 179.17517071 175.87660328 179.5223744  161.40472123
 174.16465527 168.58063922 159.48342785 190.17379458 168.96513379
 171.72529799 155.25957095 183.97047167 157.56975133 188.34529069
 170.38858718 143.31405164 185.9190679  169.51101188 155.36181972
 144.61623691 181.3892726  163.22218044 134.37177323 154.19044256
 160.45700363 142.59563772 160.37605357 171.44273535 169.70640078
 153.59534214 152.29849613 177.73804824 162.62462227 196.5989286
 162.765947   155.38582305 177.19867532 177.71711759 167.58320205
 172.24747986 165.12620889 176.47353528 187.94811592 172.89502868
 158.11438788 181.9815273  194.18043935 166.29368658 171.40764381
 178.04726676 142.06688725 159.72220239 168.75140017 171.79149347
 158.87557205 155.78707993 161.47244798 153.4709923  147.64848437
 170.51523267 173.77590858 178.25774495 140.32563393 162.97639238
 163.90251236 184.85207452 176.66444031 180.65892624 163.03595927
 151.77083121 179.13141898 171.70632128 169.38558184 172.38264989
 157.08041456 155.24917828 184.10916072 168.50840784 174.18864833
 163.74798374 158.54818729 183.45911273 159.49934259 162.99057938
 167.15176222 152.19491374 165.46079737 157.79831857 149.42032516
 178.66081158 171.26776676 178.47832146 183.10797135 141.55075244
 163.33402213 177.31821748 168.56905941 188.02853802 163.44916488
 168.17361967 179.70875574 156.75504417 160.78535928 149.1140051
 172.12819615 173.66107973 162.21543281 173.87079486 161.03824355
 175.80570369 162.87110577 161.26534934 143.54189568 175.43542171
 164.21584719 164.01339793 151.90799391 168.24579668 169.70043163
 164.26476352 170.30071889 162.32963983 172.41727919 156.12259096]

Secara default data yang dihasilkan bertipe float. Apabila menghendaki data integer bisa tambahkan .astype(int)

data_int = np.random.normal(rerata, deviasi, sampel).astype(int)
print(data_int)

Hasilnya

[162 155 171 185 143 176 157 158 187 167 179 163 156 173 160 175 151 166
 181 151 171 151 156 159 179 160 159 140 158 147 154 162 175 158 146 168
 160 177 160 157 166 173 151 161 150 170 171 135 170 201 154 177 172 154
 186 172 166 158 163 139 160 160 190 169 138 155 148 178 167 166 160 186
 165 174 139 136 164 161 154 149 139 166 159 157 172 168 194 161 158 143
 138 175 148 150 153 162 181 143 173 161 163 172 185 145 158 181 163 154
 143 176 166 176 163 147 162 161 175 177 184 169 172 146 172 134 155 162
 166 152 140 146 163 161 165 149 202 159 164 166 174 171 171 180 153 165
 165 152 166 143 163 161 156 164 150 176 175 152 152 171 144 184 168 165
 167 165 188 159 176 172 147 185 159 169 188 164 135 169 174 182 153 162
 159 154 149 183 180 180 175 141 159 179 163 193 159 182 160 173 171 177
 152 153]

 Share!

 
comments powered by Disqus