-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumPyRandom.py
48 lines (29 loc) · 1021 Bytes
/
numPyRandom.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#Generate a random integer from 0 to 100
from numpy import random
x = random.randint(100)
print(x)
#Generate Random Float
xf = random.rand()
print(xf)
#Generate a 1-D array containing 5 random integers from 0 to 100:
xia=random.randint(100, size=(5))
print(xia)
#Generate a 2-D array with 3 rows, each row containing 5 random integers from 0 to 100:
xia2 = random.randint(100, size=(3, 5))
print(xia2)
#Generate a 1-D array containing 5 random floats:
xfa = random.rand(5)
print(xfa)
#Generate a 2-D array with 3 rows, each row containing 5 random numbers:
xfa2 = random.rand(3, 5)
print(xfa2)
#Return one of the values in an array:
xrva = random.choice([3, 5, 7, 9])
print(xrva)
#Generate a 2-D array that consists of the values in the array parameter (3, 5, 7, and 9):
xrva2 = random.choice([3, 5, 7, 9], size=(3, 5))
print(xrva2)
xrdd = random.choice([3, 5, 7, 9], p=[0.1, 0.3, 0.6, 0.0], size=(100))
print(xrdd)
xrdd2 = random.choice([3, 5, 7, 9], p=[0.1, 0.3, 0.6, 0.0], size=(3, 5))
print(xrdd2)