머신러닝 및 딥러닝

numpy의 rand와 randn의 차이

AlgoPoolJa 2020. 8. 9. 22:54

numpy에서 항상 궁금했었던 것이 있다.

 

import numpy as np

A=np.random.rand
B=np.random.randn

이 둘의 차이는 무엇일까??

 

 

 

 

randn

  • Return a sample (or samples) from the “standard normal” distribution.

표준 정규 분포 ( N(0,1) 즉, 평균이 0이고 표준편차가 1인 분포) 에서 추출한 샘플을 리턴한다. 따라서 음수의 값이 나올 수 있다.

 

 

rand

  • Create an array of the given shape and populate it with random samples from a uniform distribution over [0, 1).

즉, 0은 들어가지만 1은 들어가지 않는 균등분포(각각의 변수가 나올 확률이 똑같은 분포)로 부터 랜덤한 샘플을 추출하여 배열을 반환해주는 것이다. 따라서 음수의 값이 나올 수 없다.