250x250
Link
λμ GitHub Contribution κ·Έλν
Loading data ...
Notice
Recent Posts
Recent Comments
μΌ | μ | ν | μ | λͺ© | κΈ | ν |
---|---|---|---|---|---|---|
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 |
Tags
- μλν΄λΌμ°λ
- λ°μ΄ν°λΆμ
- Python
- numpy
- datascience
- ADsP
- ADP
- λ°μ΄ν°λΆμμ λ¬Έκ°
- ν¬λ‘€λ§
- PCA
- pandas
- λ°μ΄ν°λΆκ· ν
- λΉ λ°μ΄ν°
- μ£Όμ±λΆλΆμ
- λΉ λ°μ΄ν°λΆμκΈ°μ¬
- DBSCAN
- ν μ€νΈλΆμ
- μΈλμνλ§
- νμ΄μ¬
- Lambda
- dataframe
- λμνλ³Έ
- μ€λ²μνλ§
- iloc
- κ΅°μ§ν
- LDA
- t-test
- opencv
- λ°μ΄ν°λΆμμ€μ λ¬Έκ°
- λ 립νλ³Έ
Archives
Data Science LAB
[Python] Numpy λμ μμ± (Random) λ³Έλ¬Έ
728x90
1. np.random.rand(m,n)
0~1μ κ· μΌλΆν¬ νμ€ μ κ·λΆν¬ λμλ₯Ό matrix array(m,n) ννλ‘ μμ±
import numpy as np
np.random.rand(6)
# array([0.43370799, 0.86829053, 0.43087038, 0.20789529, 0.41183189, 0.40093899])
np.random.rand(2,3)
# array([[0.69712992, 0.32758099, 0.20567256],
# [0.62130179, 0.64666152, 0.71468473]])
μ«μλ₯Ό νλλ§ μ λ ₯νλ©΄ 1μ°¨μ λ°°μ΄ ννλ‘ μμ±λ¨
2. np.random.randn(m,n)
νκ· μ΄ 0, νμ€νΈμ°¨ 1μΈ κ°μ°μμ νμ€ μ κ·λΆν¬ λμλ₯Ό matrix(m,n)ννλ‘ μμ±
np.random.randn(4)
# array([-0.41143005, 0.52455404, 0.2193374 , 1.58083578])
np.random.randn(2,4)
# array([[ 0.54727886, 1.02628151, -0.93502847, -0.65923374],
# [ 2.9750309 , 0.33535613, -0.2068257 , 1.51217218]])
3. np.random.randint(m,n,k)
μμ ~ n-1 μ¬μ΄μ λλ€ μ«μλ₯Ό kκ° λ½μ
np.random.randint(3,11,2)
# array([4, 7])
np.random.randint(3,11)
# 3
λ§μ°¬κ°μ§λ‘ kμΈμλ₯Ό μ λ ₯νμ§ μμΌλ©΄ μ«μ 1κ°λ§ μμ±ν¨
4. np.random.standard_normal()
νμ€μ κ·λΆν¬λ‘λΆν° μνλ§ λ λμλ₯Ό λ°νν¨
randn()κ³Ό λΉμ·νμ§λ§, ννμ μΈμλ‘ λ°μ
np.random.standard_normal(1,3)
# TypeError: standard_normal() takes at most 1 positional argument (2 given)
np.random.standard_normal(2)
# array([ 1.53386505, -0.59942005])
np.random.standard_normal((2,3))
# array([[-1.53569412, -0.83581106, -1.09411571],
# [-0.38692089, -0.66502681, 2.48339435]])
νν νμμ΄ μλ μΈμλ₯Ό λ°μΌλ©΄ μλ¬
5. np.random.normal(n,m,k)
μ κ·λΆν¬λ‘λΆν° μνλ§λ λμ λ°ν
N(m,m**2)μΌλ‘λΆν° μ»μ λμ kκ° λ°ν
np.random.normal(1.5, 1.5, 4)
# array([0.29619501, 2.52406325, 2.95366161, 0.02574515])
np.random.normal(3.0, 4.0, (2, 3))
# array([[ 3.61677682, 1.5624253 , -0.89876034],
# [ 5.42376827, -4.44813517, 5.60946705]])
6. np.random.random.sample()
0~1 λ²μμμ μνλ§ λ μμμ μ€μλ₯Ό λ°ν
np.random.random_sample((2,3))
# array([[0.51829587, 0.15548231, 0.21444834],
# [0.41911137, 0.40374473, 0.72714865]])
7. np.random.choice()
μ£Όμ΄μ§ 1μ°¨μ arrayλ‘λΆν° μμμ μνμ μμ±
np.random.choice(5,4)
# array([4, 1, 3, 3])
# np.arange(5)μμ λ½μ 4κ°μ μνμ 1μ°¨μ arrayλ‘ λ°ν
np.random.choice(5,(2,3))
# array([[2, 1, 3],
# [3, 0, 2]])
# np.arange(5)μμ λ½μ (2,3)νμμ arrayλ‘ λ°ν
![](https://t1.daumcdn.net/keditor/emoticon/niniz/large/043.gif)
728x90
'π Python > NumPy' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[Python] np.linspace()ν¨μ (0) | 2022.05.23 |
---|---|
[Python] NumPyλ₯Ό μ΄μ©ν νλ ¬μ μ λ ¬ (0) | 2022.02.06 |
[Python] NumPy μΈλ±μ±(Indexing) (0) | 2022.02.04 |
NumPyλ? (0) | 2022.02.03 |
Comments