#np.random.randn Generate random arrays , It changes every time it runs
arr=np.random.randn(9)
print(arr)
[ 0.2303069 1.00300936 -0.92357035 0.06525841 0.19994871 -1.40363692
0.01230236 -0.08950691 -1.13518494]
# The most value min max
print(arr.min())
print(arr.max())
-1.403636921406203
1.003009355191414
# mean value 、 Sum up 、 Sort
print(arr.mean())
print(arr.sum())
arr.sort()
print(arr)
-0.22678593093886062
-2.0410733784497457
[-1.40363692 -1.13518494 -0.92357035 -0.08950691 0.01230236 0.06525841
0.19994871 0.2303069 1.00300936]
# Create a 2D array
arr1=np.random.randn(5,3)
print(arr1)
[[-0.37967759 1.35964448 -0.91838218]
[ 0.59445228 0.50795044 -1.04871713]
[ 0.95627647 0.51861237 -1.91861238]
[ 0.71488425 0.80140304 0.85057234]
[-0.83144865 1.40915456 -0.48493178]]
# Find the maximum value , mean value , Sort
print(arr1.min())
print(arr1.mean())
arr1.sort
print(arr1)
-1.9186123788695604
0.14207870043754137
[[-0.37967759 1.35964448 -0.91838218]
[ 0.59445228 0.50795044 -1.04871713]
[ 0.95627647 0.51861237 -1.91861238]
[ 0.71488425 0.80140304 0.85057234]
[-0.83144865 1.40915456 -0.48493178]]
#linspace function : Interval bisection
np.linspace(0,10,2)
array([ 0., 10.])
np.linspace(0,10,5)
array([ 0. , 2.5, 5. , 7.5, 10. ])
# Generate 0-10 Evenly distributed between 11 Number , Include 0,10
np.linspace(0,10,11)
array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.])
#(1) Matrix multiplication dot
x=np.array([[1,2,3],[4,5,6]])
print(x)
[[1 2 3]
[4 5 6]]
y=np.array([[6,23],[-1,7],[8,9]])
print(y)
[[ 6 23]
[-1 7]
[ 8 9]]
x.dot(y) # Multiplication of matrices , Be careful : The number of rows to the left of the matrix = The number of columns in the right matrix
array([[ 28, 64],
[ 67, 181]])
#(2) Matrix inversion inv
from numpy.linalg import inv
m=np.array([[4,2],[3,1]])
print(m)
[[4 2]
[3 1]]
inv(m)
array([[-0.5, 1. ],
[ 1.5, -2. ]])
from numpy import random
# normal Method : Generate random numbers that conform to normal distribution
rArray=random.normal(size=(4,4))
print(rArray)
[[-0.06795971 -0.9353821 2.26863073 -0.75476106]
[-0.57931197 -0.35099822 0.84149375 1.55841483]
[ 1.3666115 0.16391788 -0.64410767 -1.5884498 ]
[-0.86659227 -0.60654638 1.34484013 -0.2681763 ]]
# randint Method : Generates randomly selected integers within a given upper and lower bounds
random.randint(4,10)
9
i=0
while i <20:
print(random.randint(0,2)) # Random generation 0 and 1, Each run generates a random
i+=1
0
0
0
1
1
1
0
0
0
0
1
0
1
0
0
1
1
0
1
0