sample_size = 10000
rand=np.random.rand(sample_size)
randn=np.random.randn(sample_size)
randint=np.random.randint(low=10, high=15, size=10)
random_integers=np.random.random_integers(1, 6, 10)
pdf, bins, patches = plt.hist(rand, bins=20, range=(0, 1), density=True)
plt.title('rand')
plt.show()
pdf, bins, patches = plt.hist(randn, bins=20, range=(-4, 4), density=True)
plt.title('randn')
plt.show()
pdf, bins, patches = plt.hist(randint, 10, density=True)
plt.title('randint')
plt.show()
count, bins, patches = plt.hist(random_integers, 10, density=True)
plt.title('random_integers')
plt.show()
- rand
Random values in a given shape.
np.random.rand(3,5)
>>>
array([[0.28486117, 0.29897638, 0.79203426, 0.3244706 , 0.86471039],
[0.44751263, 0.54822991, 0.35717199, 0.11231203, 0.14189715],
[0.44495908, 0.73198023, 0.46010123, 0.59274441, 0.33671386]])
- randn
Return a sample from the “standard normal” distribution.
- randint
Return random integers from low (inclusive) to high (exclusive).
np.random.randint(3,5,(3,))
>>>
array([3, 3, 4])
- random_integers
Random integers of type np.int between low and high, inclusive.
- choice
Generates a random sample from a given 1-D array.
#np.arange(5) of size 3
np.random.choice(5, 3)
>>>
array([0, 3, 4])
'Analyze Data > Python Libraries' 카테고리의 다른 글
numpy-np.c_[] VS np.r_[] (0) | 2023.05.25 |
---|---|
numpy-axis, expand_dims (0) | 2023.05.24 |
numpy-empty, where, allclose, dot, argsort, corrcoef, astype, nan, hstack, argmax (0) | 2022.12.07 |
numpy-ndim, ravel, permutation, clip, subtract (0) | 2022.05.10 |
regular expression (0) | 2022.04.26 |