np.random.rand()
: 표준 정규 분포(Standard normal distribution)로부터 샘플링(Sampling)된 난수를 반환한다.
* 난수란? 무작위로 만들어진 수열
* 표준 정규 분포란? 평균이 0이고, 표준 편차가 1인 정규분포 # N(0,1)
1) 인자가 1개일 때
np.random.rand(arg1)
: 1 x arg1 ndarray 반환
import numpy as np
print(np.random.rand(4))
np.random.rand(4).shape #(4,)
# [0.15362765 0.54915201 0.38309081 0.0309396 ]
2) 인자가 2개일 때
np.random.rand(arg1, arg2)
: arg1(행) x arg2(열) ndarray 반환
print(np.random.rand(4,3))
np.random.rand(4,3).shape #(4,3)
[[0.01304044 0.9695794 0.56967309]
[0.70221571 0.1958122 0.08068373]
[0.12818572 0.78272244 0.8335255 ]
[0.11862156 0.14117875 0.35389374]]
3) 인자가 3개일 때
np.random.rand(arg1, arg2, arg3)
: arg1(개수) x arg2(행) x arg3(열) ndarray 반환
print(np.random.rand(4,3,1))
np.random.rand(4,3,1).shape #(4,3,1)
[[[0.60756663]
[0.2319746 ]
[0.11850198]]
[[0.19399992]
[0.27819437]
[0.57692272]]
[[0.61117672]
[0.10044186]
[0.23222601]]
[[0.53610835]
[0.94366013]
[0.81449481]]]
print(np.random.rand(4,3,2))
np.random.rand(4,3,2).shape #(4,3,2)
[[[0.714514 0.38243509]
[0.35858369 0.16297643]
[0.95954249 0.55242839]]
[[0.75944037 0.14042201]
[0.3630711 0.66250145]
[0.83499042 0.13780355]]
[[0.77376779 0.34112986]
[0.65516851 0.27008747]
[0.54465844 0.64405539]]
[[0.06953998 0.37572186]
[0.3485405 0.23851377]
[0.71324777 0.29496845]]]
print(np.random.rand(4,2,4))
np.random.rand(4,2,4).shape #(4,2,4)
[[[0.75432325 0.7039253 0.08521213 0.11480493]
[0.31270955 0.31088799 0.72616086 0.06338152]]
[[0.0716085 0.73421626 0.69906589 0.12805086]
[0.47689292 0.00877446 0.86849906 0.04053276]]
[[0.55914611 0.44344352 0.39613513 0.27319254]
[0.12797766 0.86379005 0.30602653 0.96750661]]
[[0.63060983 0.02431035 0.86995266 0.23224002]
[0.29700202 0.64081752 0.19368442 0.0118656 ]]]