본문 바로가기

Numpy

Numpy - random : rand, randn

반응형
0부터 1사이의 균일분포로 랜덤한 ndarray 생성 - rand

np.random.rand(N)

0이상, 1미만
N : 크기, 튜플로 입력하면 차원을 높일 수 있다.

np.random.rand

 

 

 

N : tuple로 입력하면 2차원으로 생성 가능

 

 

3행 5열의 배열 생성

 

 

 

 

 

https://steadiness-193.tistory.com/225

 

Numpy - random : normal, uniform, randint, choice

정규분포로부터 무작위 표본 추출 - normal np.random.normal(평균, 표준편차, 크기) * 평균은 0, 표준편차는 1이 기본값 np.random.normal 난수 50개 생성 균등분포로부터 무작위 표본추출 - uniform np.random..

steadiness-193.tistory.com

 

 

위 포스팅의 np.random.uniform도 같은 기능을 할 수 있다.

 

 

 

즉, rand와 uniform의 차이는

 

uniform에선 low와 high를 조정할 수 있는 것에 있다.

 

 

 

 

 

 

 

 

가우시안 표준 정규분포로 샘플링된 ndarray 생성 - randn


np.random.randn(N)


randnn은 normal distribution(정규분포)을 의미한다.

기댓값은 0, 표준편차는 1

N : 크기, 튜플로 입력하면 차원을 높일 수 있다.

np.random.randn

 

 

정규분포형 그래프가 나온다.

 

 

 

 

이 또한 N에 튜플을 입력하면 2차원 또는 그 이상으로 만들 수 있다.

 

2차원
3차원

 

 

 

https://steadiness-193.tistory.com/225

 

Numpy - random : normal, uniform, randint, choice

정규분포로부터 무작위 표본 추출 - normal np.random.normal(평균, 표준편차, 크기) * 평균은 0, 표준편차는 1이 기본값 np.random.normal 난수 50개 생성 균등분포로부터 무작위 표본추출 - uniform np.random..

steadiness-193.tistory.com

 

 

randn 또한 위 포스팅에서의 np.random.normal이 같은 기능을 구현할 수 있다.

 

 

 

즉, randn와 np.random.normal의 차이는

 

normal에선 평균과 표준편차를 직접 입력할 수 있는데에 있다.

반응형

'Numpy' 카테고리의 다른 글

Numpy - 3차원 배열 인덱싱  (0) 2020.10.02
Numpy - apply_along_axis  (0) 2020.08.24
Numpy - random : normal, uniform, randint, choice  (0) 2020.08.12
Numpy - np.log, np.log1p, np.exp  (0) 2020.08.12
Numpy - 등간격으로 나누기 : np.linspace  (0) 2020.08.08