Scipy

Scipy_第1张图片

Scipy_第2张图片

#10.1
import numpy as np
import scipy.optimize as opt

m = 20
n = 10

A = np.random.normal(loc=10, scale=3 , size=(m,n))
b = np.random.normal(size=m)

ans = opt.lsq_linear(A, b)
x = ans['x']
residual = b - np.dot(A,x)
print(np.linalg.norm(residual))
#10.2
import numpy as np
import scipy.optimize as opt

# f(x) = sin 2(x − 2)e −x 2
def f(x):
	return -1 * np.power(np.sin(x-2), 2) * np.exp(-1*(x**2))

#the maximum of the function
res = opt.minimize_scalar(f)
x = res.x

print(-1*f(x))
#10.3
import numpy as np
import scipy.spatial.distance as distance

n = 20
m = 10

X = np.random.normal(loc = 10 , scale = 4 , size = (n, m))
ans = distance.pdist(X)
print(ans)



你可能感兴趣的:(python)