import numpy as np
from numpy import random
#create empty array
a = np.empty([3])
print(a)
[4.64136008e-310 0.00000000e+000 1.58101007e-322]
#create array with ones
a = np.ones([2,3])
print(a)
[[1. 1. 1.] [1. 1. 1.]]
#create array with zeros
a = np.zeros([3,5])
print(a)
[[0. 0. 0. 0. 0.] [0. 0. 0. 0. 0.] [0. 0. 0. 0. 0.]]
#random integer from 0 to 5
random.randint(5)
4
#array with random int from 0 to 5 and dim (3,5)
random.randint(5, size=(3, 5))
array([[2, 1, 1, 0, 3],
[4, 0, 4, 1, 2],
[0, 3, 3, 2, 3]])
#random float from 0 to 1
random.rand()
0.19057158890417292
#array with random float between 0 and 1 and dim (3,5)
random.rand(3, 5)
array([[0.77054253, 0.18653799, 0.67338338, 0.64234377, 0.34576529],
[0.75605162, 0.13783815, 0.53607811, 0.06650575, 0.36245488],
[0.80276601, 0.13417592, 0.38245341, 0.3449446 , 0.0088425 ]])
#random number from array
random.choice([3, 5, 7, 9])
3
#array with random choice from array nd dim (3,5)
random.choice([3, 5, 7, 9], size=(3, 5))
array([[3, 9, 7, 7, 3],
[3, 7, 3, 3, 7],
[3, 5, 3, 7, 5]])