Python
Python_N-002. random module
X25WLK
2025. 1. 18. 14:38
N-002_random.py
0.00MB
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) |
반응형