PYTHON CLASS - 19 - Copy
PYTHON CLASS - 19 - Copy
NUMPY RANDOM
Generating a Random Integer Number
Example:
from numpy import random
x = random.randint(100)
print(x)
Output:
32
Example 2:
from numpy import random
x = random.choice([3, 5, 7, 9], size=(3, 5))
print(x)
Output:
[[5 9 7 5 9]
[3 7 7 9 7]
[3 7 9 9 5]]
SETTING PROBABILITY
Example:
from numpy import random
x = random.choice([3, 5, 7, 9], p=[0.1, 0.9, 0.0, 0.0], size=(5))
print(x)
Output:
[5,3,5,5,5]
SHUFFLING ARRAYS
Example:
from numpy import random
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
random.shuffle(arr)
print(arr)
Output:
[5 2 3 4 1]
PERMUTATION
Example:
from numpy import random
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
print(random.permutation(arr))
Output:
[1 5 2 3 4]
SPLITTING ARRAY
Example:
import numpy as np
arr = np.array([1, 2, 3, 4, 5, 6])
newarr = np.array_split(arr, 3)
print(newarr)
Output:
[array([1, 2]), array([3, 4]), array([5, 6])]