np.random
rd = np.random.random()
rdm = np.random.random(3)
rdom = np.random.random((2, 3))
print(rd, type(rd))
print(rdm, type(rdm))
print(rdom, type(rdom))
---------
0.9793807066469438 <class 'float'>
[0.8987139 0.66990719 0.8952607 ] <class 'numpy.ndarray'>
[[0.65029784 0.08900397 0.1290881 ]
[0.50684593 0.9468616 0.01789948]] <class 'numpy.ndarray'>
rd = np.random.rand()
rdm = np.random.rand(3)
rdom = np.random.rand(2, 3)
print(rd, type(rd))
print(rdm, type(rdm))
print(rdom, type(rdom))
---------
0.6220532702098186 <class 'float'>
[0.36614729 0.18385267 0.66837204] <class 'numpy.ndarray'>
[[0.72258152 0.24918873 0.17626654]
[0.13252077 0.34055739 0.98947509]] <class 'numpy.ndarray'>
rd = np.random.randn()
rdm = np.random.randn(3)
rdom = np.random.randn(2, 3)
print(rd, type(rd))
print(rdm, type(rdm))
print(rdom, type(rdom))
---------
0.5829932781952961 <class 'float'>
[0.22367294 0.48174045 0.73252179] <class 'numpy.ndarray'>
[[ 1.09689723 0.10577242 0.14181362]
[-0.70699136 -0.12722293 0.53929664]] <class 'numpy.ndarray'>
rd = np.random.normal(1, 2)
rdm = np.random.normal(1, 2, 3)
rdom = np.random.normal(1, 2, (2, 3))
print(rd, type(rd))
print(rdm, type(rdm))
print(rdom, type(rdom))
---------
-0.3594238842620112 <class 'float'>
[ 1.38741624 4.01749899 -2.21850185] <class 'numpy.ndarray'>
[[ 4.3676994 -1.29099944 -1.00816457]
[ 0.38783973 1.49133442 3.83016246]] <class 'numpy.ndarray'>
rd = np.random.randint(10, 20)
rdm = np.random.randint(10, 20, 3)
rdom = np.random.randint(10, 20, (2, 3))
print(rd, type(rd))
print(rdm, type(rdm))
print(rdom, type(rdom))
---------
14 <class 'int'>
[11 14 16] <class 'numpy.ndarray'>
[[11 15 15]
[18 19 15]] <class 'numpy.ndarray'>
rd = np.random.uniform(10, 20)
rdm = np.random.uniform(10, 20, 3)
rdom = np.random.uniform(10, 20, (2, 3))
print(rd, type(rd))
print(rdm, type(rdm))
print(rdom, type(rdom))
---------
11.864817387392412 <class 'float'>
[19.42802607 19.80010369 16.9020914 ] <class 'numpy.ndarray'>
[[14.02833629 15.9369713 15.05197025]
[14.36971925 11.44649462 15.00716421]] <class 'numpy.ndarray'>
rd = np.random.choice([1, 2, 3, 4, 5])
rdm = np.random.choice([1, 2, 3, 4, 5], 3)
rdom = np.random.choice([1, 2, 3, 4, 5], 3, replace=False)
---------
3 <class 'numpy.int32'>
[1 1 4] <class 'numpy.ndarray'>
[3 1 5] <class 'numpy.ndarray'>
rd = [1, 2, 3, 4, 5]
np.random.shuffle(rd)
print(rd, type(rd))
---------
[5, 2, 4, 1, 3] <class 'list'>
np.random.seed(n)