Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- fancyindexing
- npy
- 배열나누기
- concat
- 표본추출
- 논리배열
- ndarray
- 배열추가
- 해커랭크
- Revising the Select Query II
- 배열자르기
- 파일저장하기
- numpy
- buit-in exception
- 배열연산
- SQL
- Revising the Select Query I
- 배열쪼개기
- 배열붙이기
- 파이썬
- CONCATENATE
- SQL문제
- Python
- 배열형태변경
- 배열분리하기
- reshape
- 랜덤샘플링
- 넘파이
- 넘파이장점
- 벡터연산
Archives
- Today
- Total
기록하는 습관
[Numpy] 010. 랜덤 표본 추출 (Random Sampling) 본문
샘플링 함수들
import numpy as np
np.random.uniform(하한, 상한, 형태)
Docstring:
uniform(low=0.0, high=1.0, size=None)
Draw samples from a uniform distribution.
Samples are uniformly distributed over the half-open interval[low, high)
(includes low, but excludes high). In other words,
any value within the given interval is equally likely to be drawn
by uniform
.
print( np.random.uniform(0, 1, 5) )
print( np.random.uniform(0, 1, (2,3)) )
[0.71029172 0.00673713 0.42074585 0.53413197 0.62083628]
[[0.46548593 0.62558901 0.2386203 ]
[0.49704519 0.06470508 0.0865601 ]]
np.random.normal(평균, 표준편차, 형태)
print( np.random.normal(0, 1, 4) )
print( np.random.normal(50, 10, (2,2)) )
print( np.random.normal(0, 1, 1000000).mean() )
[ 0.77727106 0.91040219 -0.70066303 1.31100763]
[[42.03442125 54.90997165]
[57.27299351 60.1309165 ]]
0.0004011744654032617
import pandas as pd
pd.DataFrame({"sample":np.random.normal(0, 1, 1000)}).hist()
np.random.randint(상한, 하한, 형태)
Docstring:
randint(low, high=None, size=None, dtype=int)
Return random integers from low
(inclusive) to high
(exclusive).
Return random integers from the "discrete uniform" distribution of
the specified dtype in the "half-open" interval [low
, high
). Ifhigh
is None (the default), then results are from [0, low
).
print( np.random.randint(0, 10, (3,4)) )
print( np.random.randint(0, 10, (3,1,1)) )
[[4 5 5 5]
[9 4 5 8]
[0 3 0 3]]
[[[8]]
[[3]]
[[6]]]
np.random.choice(1차원배열, 형태)
Docstring:
choice(a, size=None, replace=True, p=None)
Generates a random sample from a given 1-D array
print( np.random.choice(['가위', '바위', '보']) )
print( np.random.choice(['가위', '바위', '보'], size=0) )
print( np.random.choice(['가위', '바위', '보'], size=1) )
print( np.random.choice(['가위', '바위', '보'], size=(2,2)) )
보
[]
['바위']
[['바위' '바위']
['보' '가위']]
'Python > Numpy' 카테고리의 다른 글
[Numpy] 011. 파일 읽기&쓰기 (I/O) (0) | 2023.08.11 |
---|---|
[Numpy] 009. 불리언 배열 (Boolean Array) (0) | 2023.08.09 |
[Numpy] 008. 배열 간 연산과 브로드캐스팅 (Broadcasting) (0) | 2023.08.09 |
[Numpy] 007. 배열 내 연산 (0) | 2023.08.08 |
[Numpy] 006. 배열 자르기 (Split) (0) | 2023.08.08 |