Decription | Code Example | Output (example) |
Generate a random float between 0 and 1 |
random_float = np.random.rand() andom_array = np.random.rand(5) random_2d_array = np.random.rand(3, 4) |
0.73206853 [0.183, 0.237, ...] [[0.57, 0.84], ...] |
Generate random integers | random_int = np.random.randint(10) random_int_array = np.random.randint(1, 10, size=5) |
7 [4, 2, 6, ...] |
Normal distribution random numbers |
normal_array = np.random.randn(5) normal_array = np.random.normal(loc=0, scale=1, size=5) |
[1.56, ...] [0.1, -1.2, 0.3, ...] |
Shuffle an array | array = np.array([1, 2, 3, 4, 5]); np.random.shuffle(array) |
[3, 5, 2, 1, 4] |
Random Sample from List | np.random.sample(elements, 2) |
'Python' 카테고리의 다른 글
Python_N-004. 10 basic attributes in array (0) | 2025.01.19 |
---|---|
Python_N-003. Data Type in array (0) | 2025.01.19 |
Python_N-001. basic commend in Numpy (0) | 2025.01.18 |
Python_G-010. class vs instance (0) | 2025.01.17 |
Python_G-009. import vs from ... import vs from... import * (0) | 2025.01.17 |