scipy库练习

Ex 10.1

scipy库练习_第1张图片

Code

import numpy as np
import matplotlib.pyplot as plt
import scipy.linalg as lin

m=3
n=3
A=np.random.random((m,n))
b=np.random.random((m,1))
x,res,rnk,s=lin.lstsq(A,b)
print(lin.norm(b-A.dot(x)))

Result


Ex 10.2


Code

import scipy.optimize as opt
import numpy as np

def fun(x):
    return -(np.sin(x-2)**2)*np.e**(-x**2)

min=opt.fmin(fun,0)
print(min); 
print(-fun(min))

Result

scipy库练习_第2张图片

Ex 10.3

scipy库练习_第3张图片

Code

import numpy as np
import scipy.spatial as sp

n=3
m=3
X=np.random.random((n,m))
print(X)
print(sp.distance_matrix(X,X))

Result

scipy库练习_第4张图片

你可能感兴趣的:(scipy库练习)